<!DOCTYPE HTML>
<html lang="zh-CN">
    <!-- shw2018 XSGE  modify 2019.08.15-->



<head>
    <meta charset="utf-8">
    <meta name="keywords" content="SSM整合, 美食,莎莎,博客,日料">
    <meta name="baidu-site-verification" content="fmlEuI34ir" />
    <meta name="google-site-verification" content="KeoTn_OFy4ndJwXNmm2gMeQfPhd7alqE9vQDwI32KCY" />
    <meta name="description" content="SSM框架整合一、框架知识点回顾1.1、MyBatis核心知识点​    MyBatis 是一款优秀的==持久层框架==，它对**JDBC**操作数据库的过程进行封装，使开发者只需要关注 **SQL本身，而不需要花费精力去处理例如注册驱动、">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>SSM整合 | のブログ</title>
    <link rel="icon" type="image/x-icon, image/vnd.microsoft.icon" href="/medias/bitbug_favicon.ico">

    <link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/materialize/1.0.0/css/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/aos/3.0.0-beta.6/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/lightgallery/1.6.12/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">
    <!-- 代码高亮 -->
    <link rel="stylesheet" href="/css/prism.css">
    <script src="/js/prism.js" async></script>

    
    <style type="text/css">
        
            
            code[class*="language-"],
            pre[class*="language-"] {
                white-space: pre !important;
            }

        
    </style>

    <script src="https://lib.baomitu.com/jquery/3.2.0/jquery.min.js"></script>
    
    <!-- XSGE 为你的博客引入——今日诗词、每日一言（js插件分享） -->
    <script src="https://cdn.jsdelivr.net/npm/jinrishici@1.0.6/jinrishici.min.js" charset="utf-8"></script>
    
    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?46e79e71af0709a5b9106bf20cecc493";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
    <!-- xsge_JS -->
    
    
        <script>
            (function(){
                var bp = document.createElement('script');
                var curProtocol = window.location.protocol.split(':')[0];
                if (curProtocol === 'https') {
                    bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
                }
                else {
                    bp.src = 'http://push.zhanzhang.baidu.com/push.js';
                }
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(bp, s);
            })();
        </script>
    

<meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/sasa/atom.xml" title="のブログ" type="application/atom+xml">
</head>

    <body>

        <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <!-- 页面LOGO图标 -->
            <div class="brand-logo">
                <a href="/sasa/" class="waves-effect waves-light">
                    
                    <img src="/medias/WLogo3.png" class="logo-img" alt="LOGO">
                    
                    <!-- LOGO文字 -->
                    <span class="logo-span">のブログ</span>
                </a>
            </div>
            <!-- 导航栏 -->
            


<!-- <a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <i class="fa fa-home"></i>
            
            <span>首页</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <i class="fa fa-tags"></i>
            
            <span>标签</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <i class="fa fa-bookmark"></i>
            
            <span>分类</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/archives" class="waves-effect waves-light">
            
            <i class="fa fa-archive"></i>
            
            <span>归档</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/AV" class="waves-effect waves-light">
            
            <i class="fa fa-heartbeat"></i>
            
            <span>视听</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/galleries" class="waves-effect waves-light">
            
            <i class="fa fa-photo"></i>
            
            <span>相册</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <i class="fa fa-user-circle-o"></i>
            
            <span>关于我</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/contact" class="waves-effect waves-light">
            
            <i class="fa fa-envelope"></i>
            
            <span>留言板</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/friends" class="waves-effect waves-light">
            
            <i class="fa fa-address-book"></i>
            
            <span>友情链接</span>
        </a>
    </li>
    
    <li>
        <a href="#searchModal" class="modal-trigger waves-effect waves-light">
            <i id="searchIcon" class="fa fa-search" title="搜索"></i>
        </a>
    </li>
</ul> -->

<!-- 支持二级菜单特性 xsge shw2018 modify 2019.09.17  -->
<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right nav-menu">
    
      <li class="hide-on-med-and-down nav-item" >

        
              <a href="/" class="waves-effect waves-light">
                
                  <i class="fa fa-home"></i>
                
                <span>首页</span>
                <i class="fa fa-chevron-down" aria-hidden="true"></i>
              </a>

            <ul class="sub-nav menus_item_child ">
              
                <li> 
                  <a href="/sasa/musics" >
                    
                      <i class="fa fas fa-music" style="margin-top: -20px;"></i>
                    
                    <span>Musics</span>
                  </a>
                </li>
               
            </ul>
          
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
            <a href="/tags" class="waves-effect waves-light">
              
                <i class="fa fa-tags"></i>
              
              <span>标签</span>
              <span></span>
            </a>

            
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
            <a href="/categories" class="waves-effect waves-light">
              
                <i class="fa fa-bookmark"></i>
              
              <span>分类</span>
              <span></span>
            </a>

            
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
            <a href="/archives" class="waves-effect waves-light">
              
                <i class="fa fa-archive"></i>
              
              <span>归档</span>
              <span></span>
            </a>

            
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
              <a href="/AV" class="waves-effect waves-light">
                
                  <i class="fa fa-heartbeat"></i>
                
                <span>视听</span>
                <i class="fa fa-chevron-down" aria-hidden="true"></i>
              </a>

            <ul class="sub-nav menus_item_child ">
              
                <li> 
                  <a href="/sasa/List/music" >
                    
                      <i class="fa fa-music" style="margin-top: -20px;"></i>
                    
                    <span>音乐</span>
                  </a>
                </li>
              
                <li> 
                  <a href="/sasa/List/movies" >
                    
                      <i class="fa fa-film" style="margin-top: -20px;"></i>
                    
                    <span>视频</span>
                  </a>
                </li>
               
            </ul>
          
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
            <a href="/galleries" class="waves-effect waves-light">
              
                <i class="fa fa-photo"></i>
              
              <span>相册</span>
              <span></span>
            </a>

            
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
            <a href="/about" class="waves-effect waves-light">
              
                <i class="fa fa-user-circle-o"></i>
              
              <span>关于我</span>
              <span></span>
            </a>

            
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
            <a href="/contact" class="waves-effect waves-light">
              
                <i class="fa fa-envelope"></i>
              
              <span>留言板</span>
              <span></span>
            </a>

            
      </li>
    
      <li class="hide-on-med-and-down nav-item" >

        
            <a href="/friends" class="waves-effect waves-light">
              
                <i class="fa fa-address-book"></i>
              
              <span>友情链接</span>
              <span></span>
            </a>

            
      </li>
    

    <li>
        <a href="#searchModal" class="modal-trigger waves-effect waves-light">
            <i id="searchIcon" class="fa fa-search" title="搜索"></i>
        </a>
    </li>

</ul>

<div id="mobile-nav" class="side-nav sidenav">
    <!-- logo图标、网页标题、描述 -->
    <div class="mobile-head bg-color">
        
        <img src="/medias/WLogo3.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">のブログ</div>
        <div class="logo-desc">
            
            ササのブログ莎莎的博客，日料专家
            
        </div>
    </div>
    <!-- 导航栏，需要定义，又需要注重国际化，这个没办法使用yml配置实现 -->
    

    <!-- 一级菜单 -->
    <!-- <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-home"></i>
                
                首页
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-tags"></i>
                
                标签
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-bookmark"></i>
                
                分类
            </a>
        </li>
        
        <li>
            <a href="/archives" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-archive"></i>
                
                归档
            </a>
        </li>
        
        <li>
            <a href="/AV" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-heartbeat"></i>
                
                视听
            </a>
        </li>
        
        <li>
            <a href="/galleries" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-photo"></i>
                
                相册
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-user-circle-o"></i>
                
                关于我
            </a>
        </li>
        
        <li>
            <a href="/contact" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-envelope"></i>
                
                留言板
            </a>
        </li>
        
        <li>
            <a href="/friends" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-address-book"></i>
                
                友情链接
            </a>
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://gitee.com/xsge/sasa" class="waves-effect waves-light" target="_blank">
                <i class="fa fa-github-square fa-fw"></i>fork me
            </a>
        </li>
        
    </ul> -->

   
   
    <!-- 支持二级菜单特性 XSGE shw2018 modify 2019.09.17  -->
    <ul class="menu-list mobile-menu-list">
        <!-- 获取菜单 -->
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <!-- 二级先遍历一级，手机本一级菜单无连接地址 -->
                    <a href="javascript:;" class="waves-effect waves-light">
                        
                            <i class="fa fa-fw fa-home"></i>
                        
                        <span>首页</span>
                        <span class="m-icon"><i class="fa fa-chevron-right"></i></span>
                    </a>
                    <!-- 遍历二级菜单 -->
                    <ul class="menus_item_child ">
                        
                            <li> 
                                <a href="/sasa/musics" >
                                    
                                        <i class="fa fa-fw fas fa-music"></i>
                                    
                                    <span>Musics</span>
                                </a>
                            </li>
                         
                    </ul>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <a href="/tags" class="waves-effect waves-light">
                        <!-- 获取配置的icon图标，没有则给定一个默认的图标 -->
                        
                            <i class="fa fa-fw fa-tags"></i>
                        
                        <span>标签</span>
                    </a>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <a href="/categories" class="waves-effect waves-light">
                        <!-- 获取配置的icon图标，没有则给定一个默认的图标 -->
                        
                            <i class="fa fa-fw fa-bookmark"></i>
                        
                        <span>分类</span>
                    </a>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <a href="/archives" class="waves-effect waves-light">
                        <!-- 获取配置的icon图标，没有则给定一个默认的图标 -->
                        
                            <i class="fa fa-fw fa-archive"></i>
                        
                        <span>归档</span>
                    </a>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <!-- 二级先遍历一级，手机本一级菜单无连接地址 -->
                    <a href="javascript:;" class="waves-effect waves-light">
                        
                            <i class="fa fa-fw fa-heartbeat"></i>
                        
                        <span>视听</span>
                        <span class="m-icon"><i class="fa fa-chevron-right"></i></span>
                    </a>
                    <!-- 遍历二级菜单 -->
                    <ul class="menus_item_child ">
                        
                            <li> 
                                <a href="/sasa/List/music" >
                                    
                                        <i class="fa fa-fw fa-music"></i>
                                    
                                    <span>音乐</span>
                                </a>
                            </li>
                        
                            <li> 
                                <a href="/sasa/List/movies" >
                                    
                                        <i class="fa fa-fw fa-film"></i>
                                    
                                    <span>视频</span>
                                </a>
                            </li>
                         
                    </ul>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <a href="/galleries" class="waves-effect waves-light">
                        <!-- 获取配置的icon图标，没有则给定一个默认的图标 -->
                        
                            <i class="fa fa-fw fa-photo"></i>
                        
                        <span>相册</span>
                    </a>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <a href="/about" class="waves-effect waves-light">
                        <!-- 获取配置的icon图标，没有则给定一个默认的图标 -->
                        
                            <i class="fa fa-fw fa-user-circle-o"></i>
                        
                        <span>关于我</span>
                    </a>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <a href="/contact" class="waves-effect waves-light">
                        <!-- 获取配置的icon图标，没有则给定一个默认的图标 -->
                        
                            <i class="fa fa-fw fa-envelope"></i>
                        
                        <span>留言板</span>
                    </a>
                
            </li>
        
            <li class="m-nav-item">
                <!-- 校验是否有二级----无二级菜单 -->
                
                    <a href="/friends" class="waves-effect waves-light">
                        <!-- 获取配置的icon图标，没有则给定一个默认的图标 -->
                        
                            <i class="fa fa-fw fa-address-book"></i>
                        
                        <span>友情链接</span>
                    </a>
                
            </li>
        

        
            <li><div class="divider"></div></li>
            <li>
                <a href="https://gitee.com/xsge/sasa" class="waves-effect waves-light" target="_blank">
                    <i class="fa fa-github-square fa-fw"></i>fork me
                </a>
            </li>
        
    </ul>

</div>

        </div>
        <!-- git图标 -->
        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>
<!-- 配置导航栏右上方是否显示 fork me on github 的图标 -->
<a href="https://gitee.com/xsge/sasa" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="fork me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

        <!-- XSGE 2022.05.09 密码访问 -->

<script src="https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('请输入访问本文章的密码')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/sasa/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/9.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        SSM整合
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="https://libs.jshub.com/tocbot/4.18.2/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }
    /* 目录悬浮按钮位置 */
    #floating-toc-btn {
        position: fixed;
        right: 20px;
        bottom: 75px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- shw2018 XSGE  modify 2019.08.15-->
<!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/sasa/tags/%E6%97%A5%E6%96%99/" target="_blank">
                                <span class="chip bg-color">日料</span>
                            </a>
                        
                            <a href="/sasa/tags/Gitee/" target="_blank">
                                <span class="chip bg-color">Gitee</span>
                            </a>
                        
                            <a href="/sasa/tags/%E5%8D%9A%E5%AE%A2/" target="_blank">
                                <span class="chip bg-color">博客</span>
                            </a>
                        
                            <a href="/sasa/tags/%E6%A0%87%E7%AD%BE/" target="_blank">
                                <span class="chip bg-color">标签</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fa fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/sasa/categories/%E5%88%86%E7%B1%BB/" class="post-category" target="_blank">
                                分类
                            </a>
                        
                            <a href="/sasa/categories/%E5%88%86%E7%B1%BB/%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/" class="post-category" target="_blank">
                                软件安装与配置
                            </a>
                        
                    </div>
                    
                </div>
            </div>
            
            <div class="post-info">
                <div class="post-date info-break-policy">
                    <i class="fa fa-calendar-minus-o fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2021-09-12
                </div>

                <div class="post-author info-break-policy">
                    <i class="fa fa-user-o fa-fw"></i>作者:&nbsp;&nbsp;
                    
                        ササ
                    
                </div>

                
                    
                    <div class="info-break-policy">
                        <i class="fa fa-file-word-o fa-fw"></i>文章字数:&nbsp;&nbsp;
                        12.3k
                    </div>
                    

                    
                    <div class="info-break-policy">
                        <i class="fa fa-clock-o fa-fw"></i>阅读时长:&nbsp;&nbsp;
                        54 分
                    </div>
                    
                
                
                
                        <span id="busuanzi_container_site_pv" style='display:none'></span>
                        <i class="fa fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv" ></span>
    
                

            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="SSM框架整合"><a href="#SSM框架整合" class="headerlink" title="SSM框架整合"></a>SSM框架整合</h1><h2 id="一、框架知识点回顾"><a href="#一、框架知识点回顾" class="headerlink" title="一、框架知识点回顾"></a>一、框架知识点回顾</h2><h3 id="1-1、MyBatis核心知识点"><a href="#1-1、MyBatis核心知识点" class="headerlink" title="1.1、MyBatis核心知识点"></a>1.1、MyBatis核心知识点</h3><p>​    <strong><code>MyBatis</code></strong> 是一款优秀的==持久层框架==，它对**<code>JDBC</code>**操作数据库的过程进行封装，使开发者只需要关注 **<code>SQL</code><strong>本身，而不需要花费精力去处理例如注册驱动、创建</strong><code>Connection</code><strong>、创建</strong><code>Statement</code><strong>、手动设置参数、结果集检索等</strong><code>JDBC</code>**繁杂的过程代码。</p>
<p> **<code>MyBatis</code><strong>应用程序根据XML配置文件创建</strong><code>SqlSessionFactory</code><strong>，</strong><code>SqlSessionFactory</code><strong>在根据</strong><code>Mapper</code><strong>映射配置文件或是</strong><code>DAO</code><strong>层代码的注解，获取一个</strong><code>SqlSession</code><strong>。</strong><code>SqlSession</code><strong>包含了执行</strong><code>SQL</code><strong>所需要的所有方法，可以通过</strong><code>SqlSession</code><strong>实例直接运行映射的</strong><code>SQL</code><strong>语句，完成对数据的增删改查和事务提交等，用完之后关闭</strong><code>SqlSession</code>**。</p>
<h4 id="1-1-1、优点"><a href="#1-1-1、优点" class="headerlink" title="1.1.1、优点"></a>1.1.1、优点</h4><ol>
<li>基于**<code>SQL</code>**语法，简单易学。</li>
<li>能了解底层组装过程。</li>
<li>**<code>SQL</code>**语句封装在配置文件中，便于统一管理与维护，降低了程序的耦合度。</li>
<li>程序调试方便</li>
<li>与传统**<code>JDBC</code>**比较较少了大量的代码量，是最简单的持久化框架</li>
<li>**<code>SQL</code>**代码从程序代码中彻底分离，可重用，增强了项目中的分工，增强了移植性</li>
</ol>
<blockquote>
</blockquote>
<h4 id="1-1-2、缺点"><a href="#1-1-2、缺点" class="headerlink" title="1.1.2、缺点"></a>1.1.2、缺点</h4><ol>
<li>**<code>SQL</code>**工作量很大，尤其是字段多、关联表多时，更是如此。</li>
<li>**<code>SQL</code>**依赖于数据库，导致数据库移植性差。</li>
<li>框架还是比较简陋，功能尚有缺失，虽然简化了数据绑定代码，但是整个底层数据库查询实际还是要自己写的，工作量也比较大，而且不太容易适应快速数据库修改。 </li>
<li>二级缓存机制不佳</li>
</ol>
<blockquote>
</blockquote>
<h3 id="1-2、SpringMVC核心知识点"><a href="#1-2、SpringMVC核心知识点" class="headerlink" title="1.2、SpringMVC核心知识点"></a>1.2、SpringMVC核心知识点</h3><p>​    <strong><code>SpringMVC</code><strong>是一款基于</strong><code>MVC</code><strong>思想的应用框架，它是</strong><code>Spring </code><strong>的一个子框架。属于</strong><code>Spring </code><strong>的一部分，</strong><code>SpringMVC</code><strong>的运行依赖</strong><code>Spring </code><strong>，==两者之间无须第三方整合==。在</strong><code>MVC</code><strong>设计模式中，</strong><code>SpringMVC</code><strong>作为==控制器==(</strong><code>Controller</code></strong>)来建立模型与视图的数据交互。【直接点就是功能类似于**<code>Servlet</code><strong>】。其核心就是使用前端控制器</strong><code>DispatcherServlet</code>**。</p>
<h4 id="1-2-1、执行思路"><a href="#1-2-1、执行思路" class="headerlink" title="1.2.1、执行思路"></a>1.2.1、执行思路</h4><p><img src="/SSM%E6%95%B4%E5%90%88/springMVC%E8%AE%BF%E9%97%AE%E7%A4%BA%E4%BE%8B.png" alt="SpringMVC访问示例图"></p>
<ol>
<li>前端控制器**<code>DispatcherServlet</code>**接受客户端浏览器发送的请求。</li>
<li>前端控制器**<code>DispatcherServlet</code><strong>调用处理器映射器</strong><code>HandlerMapping</code>**查找相应的处理器。</li>
<li>处理器映射器根据**<code>URL</code><strong>查找处理器</strong><code>Handler</code><strong>，并给前端控制器返回生成的处理器和相应的处理器拦截器</strong><code>HandlerIntercepter</code>**。</li>
<li>前端控制器调用处理器适配器**<code>HandlerAdapter</code>**。</li>
<li>处理器适配器调用相应的处理器。</li>
<li>处理器给处理器适配器返回**<code>ModelAndView</code>**(包含逻辑视图名) 。</li>
<li>处理器将**<code>ModelAndView</code>**返回给前端控制器 。</li>
<li>前端控制器将**<code>ModelAndView</code><strong>传给视图解析器</strong><code>ViewResolver </code>**。</li>
<li>视图解析器**<code>ViewResolver </code><strong>解析后将具体的视图</strong><code>View</code>**返回给前端控制器 。</li>
<li>前端控制器对视图进行渲染（视图渲染：将模型数据（在**<code>ModelAndView</code><strong>中）填充到</strong><code>request</code>**域中）。</li>
<li>前端控制器将视图返回给客户端浏览器。</li>
</ol>
<h4 id="1-2-2、Spring-MVC的优势"><a href="#1-2-2、Spring-MVC的优势" class="headerlink" title="1.2.2、Spring MVC的优势"></a>1.2.2、Spring MVC的优势</h4><ol>
<li>清晰的角色划分：前端控制器（**<code>DispatcherServlet</code><strong>），请求到处理器映射（</strong><code>HandlerMapping</code><strong>），处理器适配器（</strong><code>HandlerAdapter</code><strong>），视图解析器（</strong><code>ViewResolver </code><strong>），处理器或页面控制器（</strong><code>Controller</code><strong>），验证器（</strong><code>Validator</code><strong>），命令对象（</strong><code>Command</code><strong>请求参数绑定到的对象就叫命令对象），表单对象（</strong><code>Form Object</code>**提供给表单展示和提交到的对象就叫表单对象）。</li>
<li>分工明确，而且扩展点相当灵活，可以很容易扩展，虽然几乎不需要</li>
<li>由于命令对象就是一个**<code>POJO</code><strong>，无需继承框架特定</strong><code>API</code>**，可以使用命令对象直接作为业务对象</li>
<li>==和**<code>Spring </code>**框架无缝结合==，是其他web框架所不具备的</li>
<li>可适配，通过**<code>HandlerAdapter</code>**可以支持任意的类作为处理器</li>
<li>可定制行，**<code>HandlerMapping</code><strong>，</strong><code>ViewResolver </code>**等能够非常简单的定制</li>
<li>功能强大的数据验证，格式化，绑定机制；</li>
<li>利用**<code>Spring </code><strong>提供的</strong><code>Mock</code><strong>对象能够非常简单的进行</strong>WEB**层单元测试；</li>
<li>本地化，主题的解析的支持，使我们更容易进行国际化和主题的切换；</li>
<li>强大的**<code>JSP</code><strong>标签库，使</strong><code>JSP</code>**编写更容易。</li>
</ol>
<h4 id="1-2-3、SpringMVC常用注解："><a href="#1-2-3、SpringMVC常用注解：" class="headerlink" title="1.2.3、SpringMVC常用注解："></a>1.2.3、SpringMVC常用注解：</h4><p><strong><code>@Controller</code></strong><br>　　负责注册一个**<code>bean </code><strong>到</strong><code>Spring </code><strong>上下文中。在</strong><code>Spring </code><strong>中注册</strong><code>Controller</code>**对象。</p>
<p><strong><code>@RequestMapping</code></strong><br>　　负责控制器指定可以处理哪些 **<code>URL</code><strong>请求（设定请求方法访问</strong><code>URL</code>**）</p>
<p><strong><code>@RequestBody</code></strong><br>　　该注解用于读取**<code>request</code><strong>请求体中的部分数据，使用系统默认配置的</strong><code>HttpMessageConverter</code><strong>进行解析，然后把相应的数据绑定到要返回的对象上 ,再把</strong><code>HttpMessageConverter</code>**返回的对象数据绑定到 **<code>Controller</code><strong>中方法的参数上（请求数据转为</strong><code>JSON</code><strong>传递给</strong><code>Controller</code>**中方法的参数上）</p>
<p><strong><code>@ResponseBody</code></strong><br>　　 该注解用于将**<code>Controller</code><strong>的方法返回的对象，通过适当的</strong><code>HttpMessageConverter</code><strong>转换为指定格式后，写入到</strong><code>response</code><strong>对象的</strong><code>body</code><strong>数据区（响应数据对象转为</strong><code>JSON</code>**）</p>
<h3 id="1-3、Spring核心知识点"><a href="#1-3、Spring核心知识点" class="headerlink" title="1.3、Spring核心知识点"></a>1.3、Spring核心知识点</h3><p>​    **<code>Spring </code><strong>是一个分层的、开源的轻量级框架。</strong><code>Spring</code>**的核心有两部分：==控制反转、面向切面==。</p>
<h4 id="1-3-1、IOC（Inversion-on-Control）意思是控制反转："><a href="#1-3-1、IOC（Inversion-on-Control）意思是控制反转：" class="headerlink" title="1.3.1、IOC（Inversion on Control）意思是控制反转："></a>1.3.1、IOC（Inversion on Control）意思是控制反转：</h4><p>​    举例来说，在之前的操作中，比方说有一个类，我们想要调用类里面的方法(不是静态方法)，就要创建类的对象，使用对象调用方法实现。对于**<code>Spring</code><strong>来说，</strong><code>Spring</code><strong>创建对象的过程，不是在代码里面实现的，而是交给</strong><code>Spring</code>**来进行配置实现的。</p>
<h4 id="1-3-2、AOP（Aspect-Oriented-Programming）：面向切面编程。"><a href="#1-3-2、AOP（Aspect-Oriented-Programming）：面向切面编程。" class="headerlink" title="1.3.2、AOP（Aspect Oriented Programming）：面向切面编程。"></a>1.3.2、AOP（Aspect Oriented Programming）：面向切面编程。</h4><p>​    主要是管理==系统层的业务==，比如日志，权限，事物等。**<code>AOP</code><strong>是将封装好的对象剖开，找出其中对多个对象产生影响的公共行为，并将其封装为一个可重用的模块，这个模块被命名为切面（</strong><code>aspect</code>**），切面将那些与业务逻辑无关，却被业务模块共同调用的逻辑提取并封装起来，减少了系统中的重复代码，降低了模块间的耦合度，同时提高了系统的可维护性。</p>
<h4 id="1-3-3、为什么使用Spring"><a href="#1-3-3、为什么使用Spring" class="headerlink" title="1.3.3、为什么使用Spring"></a>1.3.3、为什么使用Spring</h4><ol>
<li>方便解耦，简化开发。 **<code>Spring</code><strong>就是一个大工厂，可以将所有对象的创建和依赖关系的维护，交给</strong><code>Spring</code>**管理。</li>
<li>**<code>AOP</code><strong>编程的支持 。</strong><code>Spring</code>**提供面向切面编程，可以方便的实现对程序进行权限拦截、运行监控等功能。</li>
<li>声明式事务的支持。只需要通过配置就可以完成对事务的管理，而无须手动编程。</li>
<li>方便程序的测试 。**<code>Spring</code><strong>对</strong><code>Junit4</code><strong>支持，可以通过注解方便的测试</strong><code>Spring</code>**程序。</li>
<li>方便集成各种优秀的框架 。**<code>Spring</code><strong>不排斥各种优秀的开源框架，其内部提供了对各种优秀框架的直接支持(如：</strong><code>Struts2、Hibernate、MyBatis、Quartz</code>**等)。</li>
<li>降低**<code>JavaEE API</code><strong>的使用难度 。</strong><code>Spring</code><strong>对</strong><code>JavaEE</code><strong>开发中非常难用的一些</strong><code>API</code><strong>（</strong><code>JDBC、JavaMail、</code><strong>远程调用等），都提供了封装，使这些</strong><code>API</code>**应用难度大大降低。</li>
</ol>
<h4 id="1-3-4、常用的Spring注解"><a href="#1-3-4、常用的Spring注解" class="headerlink" title="1.3.4、常用的Spring注解"></a>1.3.4、常用的Spring注解</h4><p>​    **<code>@Service</code>**用于标注业务层组件。</p>
<p>​    **<code>@Controller</code><strong>用于标注控制层组件（如</strong><code>struts</code><strong>中的</strong><code>action</code><strong>，</strong><code>SpringMVC</code><strong>中的</strong><code>Controller</code>**）</p>
<p>​    **<code>@Repository</code><strong>用于标注数据访问组件，即</strong><code>DAO</code>**组件。</p>
<p>​    **<code>@Component</code>**泛指组件，当组件不好归类的时候，我们可以使用这个注解进行标注。</p>
<p>​    **<code>@Resource</code>**默认按名称装配，当找不到与名称匹配的bean才会按类型装配。</p>
<p>​    **<code>@Autowired </code>**默认按类型装配，如果我们想使用按名称装配，可以结合@Qualifier注解一起使用。如下：</p>
<blockquote>
<p>[^@Autowired扩展说明：]: **<code>@Autowired @Qualifier(&quot;personDaoBean&quot;) </code>**存在多个实例配合使用</p>
</blockquote>
<h1 id="一、SSM整合思想"><a href="#一、SSM整合思想" class="headerlink" title="一、SSM整合思想"></a>一、SSM整合思想</h1><p><strong><code>MyBatis+Spring+Spring MVC</code><strong>整合简称</strong><code>SSM</code></strong></p>
<p><img src="/SSM%E6%95%B4%E5%90%88/ssm%E6%95%B4%E5%90%88%E5%9B%BE%E8%A7%A3.jpg" alt="SSM整合思想图解"></p>
<p>1、<strong>SSM整合步骤参考</strong></p>
<ol>
<li>搭建**<code>SpringMVC</code><strong>环境。（控制器）==</strong><code>5.2.5</code>**==</li>
<li>加入**<code>MyBatis</code>** 。（持久层）==<strong><code>3.4.6</code></strong>==</li>
<li>加入**<code>Spring </code><strong>。（依赖注入，事务——业务处理）==</strong><code>5.2.5</code>**==</li>
<li>整合Spring与MyBatis以及优化业务层</li>
</ol>
<blockquote>
<p><a href="%E6%89%80%E6%9C%89**%60SQL%60**%E8%AF%AD%E5%8F%A5%EF%BC%8C%E5%85%A8%E9%83%A8%E5%AE%9A%E4%B9%89%E5%9C%A8**%60xml%60**%E4%B8%AD%EF%BC%88%E6%8E%A8%E8%8D%90%EF%BC%89%E3%80%82%E4%B9%9F%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E6%B3%A8%E8%A7%A3%E7%9A%84%E6%96%B9%E5%BC%8F%E5%9C%A8%E6%8E%A5%E5%8F%A3%E4%B8%8A%E5%AE%9E%E7%8E%B0%E3%80%82%E8%BF%99%E4%BA%9B%E6%98%A0%E5%B0%84%E6%96%87%E4%BB%B6%E7%A7%B0%E4%B9%8B%E4%B8%BA**%60Mapper%60**">^说明</a>: SpringMVC 本身就是Spring中的一个子项目，所以==Spring与SpringMVC之间最大的优势在于无缝结合==，无需第三方整合。</p>
</blockquote>
<p>2、<strong>分工说明</strong></p>
<p>​    **<code>SpringMVC</code><strong>：作为 <strong><code>View</code></strong> 层的实现者，完成用户的请求接收功能。</strong><code>SpringMVC</code><strong>中的</strong><code>Controller</code>**作为整个应用的控制器，完成用户请求的转发及对用户的响应</p>
<p>​    <strong><code>MyBatis</code></strong> ：作为 **<code>DAO</code>**层的实现者，完成对数据库的增、删、改、查功能</p>
<p>​    **<code>Spring </code>**：以整个应用大管家的身份出现。整个应用中所有 <strong><code>Bean</code><strong>的生命周期行为，均由</strong><code>Spring </code></strong> 来管理。即整个应用中所有对象的创建、初始化、销毁，及对象间关联关系的维护，均由 **<code>Spring </code>**进行管理。</p>
<p>总结：</p>
<p>**<code>SpringMVC</code>**：负责业务流程控制（接收请求，跳转，响应等）。</p>
<p><strong><code>MyBatis</code></strong> ：负责数据库交互。</p>
<p>**<code>Spring </code>**：负责整个项目中所有对象的初始化，以及业务处理（事务控制）。</p>
<h1 id="二、SSM整合实现"><a href="#二、SSM整合实现" class="headerlink" title="二、SSM整合实现"></a>二、SSM整合实现</h1><h2 id="2-1、新建Mavne之WEB项目"><a href="#2-1、新建Mavne之WEB项目" class="headerlink" title="2.1、新建Mavne之WEB项目"></a>2.1、新建Mavne之WEB项目</h2><p>**<code>SSM</code><strong>整合属于</strong><code>WEB</code>**项目。</p>
<h3 id="2-1-1、第一步：新建WEB项目"><a href="#2-1-1、第一步：新建WEB项目" class="headerlink" title="2.1.1、第一步：新建WEB项目"></a>2.1.1、第一步：新建WEB项目</h3><p>​    新建**<code>WEB</code><strong>项目。（本次演示使用</strong><code>Maven</code>**项目）</p>
<p><img src="/SSM%E6%95%B4%E5%90%88/1%E3%80%81ssm%E6%96%B0%E5%BB%BAMaven%E9%A1%B9%E7%9B%AE.png" alt="新建WEB项目"></p>
<h3 id="2-1-2、第二步：更改WEB项目基础模板和版本"><a href="#2-1-2、第二步：更改WEB项目基础模板和版本" class="headerlink" title="2.1.2、第二步：更改WEB项目基础模板和版本"></a>2.1.2、第二步：更改WEB项目基础模板和版本</h3><p>​    <strong><code>Mavne</code><strong>新建</strong><code>WEB</code><strong>项目，默认版本为</strong>2.5</strong>不支持**<code>Servlet3.0</code>**注解。所以更改项目版本。</p>
<p><img src="/SSM%E6%95%B4%E5%90%88/2%E3%80%81%E6%9B%B4%E6%94%B9%E9%A1%B9%E7%9B%AE%E7%89%88%E6%9C%AC.png" alt="更改WEB版本"></p>
<h3 id="2-1-3、第三步：引入WEB项目所需依赖"><a href="#2-1-3、第三步：引入WEB项目所需依赖" class="headerlink" title="2.1.3、第三步：引入WEB项目所需依赖"></a>2.1.3、第三步：引入WEB项目所需依赖</h3><p>​    如果是普通的**<code>WEB</code><strong>项目，则无序关注这一步，如果是</strong><code>Maven</code><strong>项目则需要引入</strong><code>WEB</code><strong>开发环境依赖。</strong><code>Servlet-API、JSTL</code>**等。</p>
<ol>
<li>**<code>Servlet-API</code><strong>：</strong><code>WEB</code>**开发依赖</li>
<li>**<code>JSTL</code>**：标签库（该依赖引入时切忌不要错了：有坑）</li>
<li>**<code>Junit</code>**：测试</li>
<li>配置**<code>Tomcat</code>**插件</li>
</ol>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>project</span> <span class="token attr-name">xmlns</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://maven.apache.org/POM/4.0.0<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">xsi:</span>schemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>modelVersion</span><span class="token punctuation">></span></span>4.0.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>modelVersion</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>xsge<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>ssm01<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>0.0.1-SNAPSHOT<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>packaging</span><span class="token punctuation">></span></span>war<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>packaging</span><span class="token punctuation">></span></span>
  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">></span></span>
  	<span class="token comment">&lt;!-- #######################  WEB组件  ###################### --></span>
  	<span class="token comment">&lt;!-- 引入WEB开发依赖Servlet-API --></span>
    <span class="token comment">&lt;!-- https://mvnrepository.com/artifact/javax/javaee-api --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>javax<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>javaee-api<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>7.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>provided<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>

    <span class="token comment">&lt;!-- 引入WEB开发依赖JSTL.jar --></span>	
    <span class="token comment">&lt;!-- https://mvnrepository.com/artifact/jstl/jstl --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>jstl<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>jstl<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>

      <span class="token comment">&lt;!-- 引入测试依赖Junit.jar --></span>
    <span class="token comment">&lt;!-- https://mvnrepository.com/artifact/junit/junit --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>junit<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>junit<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>4.12<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>
    
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">></span></span>
  
  <span class="token comment">&lt;!-- #################################   配置Tomcat插件   ################################ --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>build</span><span class="token punctuation">></span></span>     
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugins</span><span class="token punctuation">></span></span>   
    	<span class="token comment">&lt;!-- 也可以局部配置JDK版本，编译版本等。（没有在Maven中配置） --></span>        
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>plugin</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.apache.tomcat.maven<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>tomcat7-maven-plugin<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>configuration</span><span class="token punctuation">></span></span>
                <span class="token comment">&lt;!-- 指定端口 --></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>port</span><span class="token punctuation">></span></span>8080<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>port</span><span class="token punctuation">></span></span>
                <span class="token comment">&lt;!-- 请求路径 --></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>path</span><span class="token punctuation">></span></span>/ssm01<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>path</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>configuration</span><span class="token punctuation">></span></span>                
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugin</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>plugins</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>build</span><span class="token punctuation">></span></span>
  
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>project</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
<p>常见错误：JSTL引入依赖的坑。不要引入javax.servlet.jsp.jstl……这个引入后会报错：依赖冲突，还有版本兼容冲突。</p>
</blockquote>
<h3 id="2-1-4、新建开发MVC目录结构"><a href="#2-1-4、新建开发MVC目录结构" class="headerlink" title="2.1.4、新建开发MVC目录结构"></a>2.1.4、新建开发MVC目录结构</h3><p>​    新建**<code>index.jsp</code>**测试主页，新建开发目录结构。</p>
<pre class="line-numbers language-jsp" data-language="jsp"><code class="language-jsp">&lt;%@ page language&#x3D;&quot;java&quot; contentType&#x3D;&quot;text&#x2F;html; charset&#x3D;UTF-8&quot;
    pageEncoding&#x3D;&quot;UTF-8&quot;%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset&#x3D;&quot;UTF-8&quot;&gt;
&lt;title&gt;Insert title here&lt;&#x2F;title&gt;
&lt;&#x2F;head&gt;
&lt;body&gt;
	&lt;h1&gt;SSM整合测试&lt;&#x2F;h1&gt;
&lt;&#x2F;body&gt;
&lt;&#x2F;html&gt;<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>​    此处目录结构是**<code>Maven</code><strong>项目。（说明：</strong><code>DAO</code><strong>层与</strong><code>Service</code>**层都需要接口及实现类）</p>
<p><img src="/SSM%E6%95%B4%E5%90%88/3%E3%80%81WEB%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84.png" alt="WEB开发目录结构"></p>
<h3 id="2-1-5、启动服务测试访问"><a href="#2-1-5、启动服务测试访问" class="headerlink" title="2.1.5、启动服务测试访问"></a>2.1.5、启动服务测试访问</h3><p>​    配置并启动**<code>IDE</code><strong>开发工具集成的</strong><code>Tomcat</code><strong>服务，或启动</strong><code>Maven</code><strong>环境插件中的</strong><code>Tomcat</code><strong>服务。（这里演示的是</strong><code>Maven</code>**）</p>
<p><img src="/SSM%E6%95%B4%E5%90%88/4%E3%80%81%E5%90%AF%E5%8A%A8WEB%E6%B5%8B%E8%AF%95%E8%AE%BF%E9%97%AE.png" alt="启动Tomcat服务测试WEB项目"></p>
<p>​    访问地址：</p>
<h2 id="2-2、整合之加入Spring-MVC环境"><a href="#2-2、整合之加入Spring-MVC环境" class="headerlink" title="2.2、整合之加入Spring MVC环境"></a>2.2、整合之加入Spring MVC环境</h2><p>​    略：可以参考**<code>Spring MVC</code><strong>的</strong><code>HelloWord</code><strong>程序。（后期会用到</strong><code>JSON</code>**,所以注意引入该依赖）</p>
<h3 id="2-2-1、引入SpringMVC依赖jar"><a href="#2-2-1、引入SpringMVC依赖jar" class="headerlink" title="2.2.1、引入SpringMVC依赖jar"></a>2.2.1、引入SpringMVC依赖jar</h3><p>​    在仓库搜索**<code>Spring Web MVC</code><strong>，修改</strong><code>pom.xml</code><strong>核心配置文件引入依赖==</strong><code>5.2.5</code><strong>==版本（该依赖，会自动导入其他</strong><code>Spring MVC</code>**的依赖）。当然如果不愿意，也可以自己一个一个的引入。</p>
<p><img src="/SSM%E6%95%B4%E5%90%88/5%E3%80%81SpringMVC%E4%BE%9D%E8%B5%96.png" alt="Spring MVC依赖"></p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- #################################   Spring MVC   ################################ --></span>
<span class="token comment">&lt;!-- 引入Spring MVC依赖https://mvnrepository.com/artifact/org.springframework/spring-webmvc --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-webmvc<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>5.2.5.RELEASE<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>
<span class="token comment">&lt;!-- #######################  JSON依赖（引入这一项将自动引入其他依赖）   ###################### --></span>
<span class="token comment">&lt;!-- 引入JSON依赖https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>com.fasterxml.jackson.core<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>jackson-databind<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>2.9.10<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
<p>[^引入说明]: Spring MVC 与 JSON存在依存和是否支持关系，因此请在使用版本过程中注意版本兼容性问题。经测试，Spring MVC（4.x、5.x）与JSON（==2.9.x==）可兼容。更高版本的JSON不兼容，引入后会报错（ClassFormatException）。</p>
</blockquote>
<h3 id="2-2-2、新建SpringMVC核心配置文件"><a href="#2-2-2、新建SpringMVC核心配置文件" class="headerlink" title="2.2.2、新建SpringMVC核心配置文件"></a>2.2.2、新建SpringMVC核心配置文件</h3><ol>
<li>新建**<code>Spring MVC</code>**核心配置文件。</li>
<li>配置开启注解扫描。</li>
<li>配置视图解析器**<code>InternalResourceViewResolver</code>**。</li>
<li>配置启用注解驱动。</li>
</ol>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>beans</span> <span class="token attr-name">xmlns</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/beans<span class="token punctuation">"</span></span>
       <span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span>
       <span class="token attr-name"><span class="token namespace">xmlns:</span>context</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/context<span class="token punctuation">"</span></span>
       <span class="token attr-name"><span class="token namespace">xmlns:</span>aop</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/aop<span class="token punctuation">"</span></span>
       <span class="token attr-name"><span class="token namespace">xmlns:</span>tx</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/tx<span class="token punctuation">"</span></span>
       <span class="token attr-name"><span class="token namespace">xmlns:</span>mvc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/mvc<span class="token punctuation">"</span></span>
       <span class="token attr-name"><span class="token namespace">xsi:</span>schemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 开启控制器注解扫描，use-default-filters：默认为true扫描全部包 --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">context:</span>component-scan</span> <span class="token attr-name">base-package</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm.controller<span class="token punctuation">"</span></span> <span class="token attr-name">use-default-filters</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>false<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置只扫描使用了Controller的注解类 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">context:</span>include-filter</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>annotation<span class="token punctuation">"</span></span> <span class="token attr-name">expression</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.springframework.stereotype.Controller<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">context:</span>component-scan</span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 配置视图解析器，实现页面跳转 --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>viewResolver<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.springframework.web.servlet.view.InternalResourceViewResolver<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>prefix<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/WEB-INF/page/<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>suffix<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>.jsp<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bean</span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 配置开启注解驱动 --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>annotation-driven</span><span class="token punctuation">/></span></span>
	
	<span class="token comment">&lt;!-- 配置将Spring MVC无法处理的请求（404）等交由Tomcat中默认的Servlet处理 --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>default-servlet-handler</span><span class="token punctuation">/></span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>beans</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2-2-3、在web-xml中配置Spring-MVC"><a href="#2-2-3、在web-xml中配置Spring-MVC" class="headerlink" title="2.2.3、在web.xml中配置Spring MVC"></a>2.2.3、在web.xml中配置Spring MVC</h3><ol>
<li>配置核心前端控制器**<code>DispatcherServlet</code>**。</li>
<li>配置编码拦截处理器**<code>CharacterEncodingFilter</code>**。</li>
<li>配置支持**<code>RESTFUL</code><strong>风格多种不同请求的拦截器</strong><code>HiddenHttpMethodFilter</code>**。</li>
</ol>
<blockquote>
</blockquote>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>web-app</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>WebApp_ID<span class="token punctuation">"</span></span> <span class="token attr-name">version</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>3.1<span class="token punctuation">"</span></span>
	<span class="token attr-name">xmlns</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://xmlns.jcp.org/xml/ns/javaee<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xsi:</span>schemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
	<span class="token comment">&lt;!-- ++++++++ Spring MVC核心配置：前端控制器Servlet ++++++ --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>dispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-class</span><span class="token punctuation">></span></span>org.springframework.web.servlet.DispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-class</span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置加载Spring MVC核心配置文件 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>contextConfigLocation<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>
			<span class="token comment">&lt;!-- spring mvc核心配置文件地址 --></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>classpath:springmvc-config.xml<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置加载时机 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>load-on-startup</span><span class="token punctuation">></span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>load-on-startup</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-mapping</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>dispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-mapping</span><span class="token punctuation">></span></span>


	<span class="token comment">&lt;!-- ++++++++ 配置Spring MVC核心编码处理拦截器 +++++++++ --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>characterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-class</span><span class="token punctuation">></span></span>org.springframework.web.filter.CharacterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-class</span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置使用编码 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>encoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>UTF-8<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置是否开启请求编码处理 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>forceRequestEncoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置是否开启响应编码处理 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>forceResponseEncoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-mapping</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>characterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/*<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-mapping</span><span class="token punctuation">></span></span>

    <span class="token comment">&lt;!-- ++++++++++++++  配置支持RESTFUL风格的多种请求方式的过滤器 +++++++++++++++ --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>HiddenHttpMethodFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-class</span><span class="token punctuation">></span></span>org.springframework.web.filter.HiddenHttpMethodFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-class</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-mapping</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>HiddenHttpMethodFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/*<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-mapping</span><span class="token punctuation">></span></span>


	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>welcome-file-list</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>welcome-file</span><span class="token punctuation">></span></span>index.jsp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>welcome-file</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>welcome-file-list</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>web-app</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="附录：前端控制器和编码处理器的其他配置方式"><a href="#附录：前端控制器和编码处理器的其他配置方式" class="headerlink" title="附录：前端控制器和编码处理器的其他配置方式"></a>附录：前端控制器和编码处理器的其他配置方式</h4><ul>
<li><strong><code>前端控制器配置</code></strong></li>
</ul>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- ++++++++ Spring MVC核心配置：前端控制器Servlet ++++++ --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>dispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-class</span><span class="token punctuation">></span></span>org.springframework.web.servlet.DispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-class</span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!-- 没有配置加载Spring MVC核心配置文件，Spring MVC默认会自动去加载WEB-INF根目录下名为：dispatcherServlet-Servlet.xml的文件 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>load-on-startup</span><span class="token punctuation">></span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>load-on-startup</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-mapping</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>dispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-mapping</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
<p>要求：</p>
<ol>
<li><p>配置文件名必须为：Servlet配置名+“-Servlet”+xml。</p>
<p>例如：Servlet配置名为dispatcherServlet，那么配置文件名必须为：dispatcherServlet-Servlet.xml</p>
</li>
<li><p>文件必须放置在WEB-INF根目录下。</p>
</li>
</ol>
</blockquote>
<ul>
<li><strong>编码拦截器处理器</strong></li>
</ul>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 配置处理Spring MVC请求编码乱码问题 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter</span><span class="token punctuation">></span></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>characterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-class</span><span class="token punctuation">></span></span>org.springframework.web.filter.CharacterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-class</span><span class="token punctuation">></span></span>  
  <span class="token comment">&lt;!-- 配置参数设置指定编码 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>encoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>UTF-8<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>  
  <span class="token comment">&lt;!-- 配置是否开启请求编码处理：这是低版本的配置  --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>forceEncoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>  
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter</span><span class="token punctuation">></span></span>
<span class="token comment">&lt;!-- 配置拦截器映射：拦截所有请求 --></span>  
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-mapping</span><span class="token punctuation">></span></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>characterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/*<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>  
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-mapping</span><span class="token punctuation">></span></span> <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
<p><a href="%E6%89%80%E6%9C%89**%60SQL%60**%E8%AF%AD%E5%8F%A5%EF%BC%8C%E5%85%A8%E9%83%A8%E5%AE%9A%E4%B9%89%E5%9C%A8**%60xml%60**%E4%B8%AD%EF%BC%88%E6%8E%A8%E8%8D%90%EF%BC%89%E3%80%82%E4%B9%9F%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E6%B3%A8%E8%A7%A3%E7%9A%84%E6%96%B9%E5%BC%8F%E5%9C%A8%E6%8E%A5%E5%8F%A3%E4%B8%8A%E5%AE%9E%E7%8E%B0%E3%80%82%E8%BF%99%E4%BA%9B%E6%98%A0%E5%B0%84%E6%96%87%E4%BB%B6%E7%A7%B0%E4%B9%8B%E4%B8%BA**%60Mapper%60**">^说明</a>: 该配置属于较早版本的Spring MVC的配置，当然新版本的也适用。拦截器初始化参数只需要配置一个即可</p>
</blockquote>
<h3 id="2-2-4、测试Spring-MVC环境支持"><a href="#2-2-4、测试Spring-MVC环境支持" class="headerlink" title="2.2.4、测试Spring MVC环境支持"></a>2.2.4、测试Spring MVC环境支持</h3><ol>
<li>在**<code>WEB-INF</code>**根目录下新建请求跳转目录及页面。</li>
<li>新建测试**<code>Controller</code>**。</li>
<li>编写测试主页**<code>index.jsp</code>**</li>
<li>启动服务访问测试主页。</li>
</ol>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token annotation punctuation">@Controller</span>
<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/test"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ControllerTest</span> <span class="token punctuation">&#123;</span>
	<span class="token comment">/**
	 * 编写Controller测试SrpingMVC环境
	 **/</span>
	<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/springMVCTest"</span><span class="token punctuation">)</span>
  <span class="token comment">// @ResponseBody 测试JSON</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">springMVCTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"springMVCTest测试Spring MVC环境"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token string">"springMVCTest"</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>测试主页</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span>SSM整合环境测试主页<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>$&#123;pageContext.request.contextPath&#125;/test/springMVCTest<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>测试Spring MVC环境<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>

<h2 id="2-3、整合之加入MyBatis环境"><a href="#2-3、整合之加入MyBatis环境" class="headerlink" title="2.3、整合之加入MyBatis环境"></a>2.3、整合之加入MyBatis环境</h2><p>​    **<code>MyBatis</code>**属于持久层操作，所以即需要注意数据库问题。</p>
<h3 id="2-3-1、设计简单的数据库"><a href="#2-3-1、设计简单的数据库" class="headerlink" title="2.3.1、设计简单的数据库"></a>2.3.1、设计简单的数据库</h3><pre class="line-numbers language-sql" data-language="sql"><code class="language-sql"><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token identifier"><span class="token punctuation">`</span>ssmtest01<span class="token punctuation">`</span></span> <span class="token punctuation">(</span>
  <span class="token identifier"><span class="token punctuation">`</span>sid<span class="token punctuation">`</span></span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
  <span class="token identifier"><span class="token punctuation">`</span>sname<span class="token punctuation">`</span></span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  <span class="token identifier"><span class="token punctuation">`</span>sage<span class="token punctuation">`</span></span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  <span class="token identifier"><span class="token punctuation">`</span>spassword<span class="token punctuation">`</span></span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  <span class="token identifier"><span class="token punctuation">`</span>saddress<span class="token punctuation">`</span></span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token identifier"><span class="token punctuation">`</span>sid<span class="token punctuation">`</span></span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8

<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> ssmtest01<span class="token punctuation">(</span>sname<span class="token punctuation">,</span>sage<span class="token punctuation">,</span>spassword<span class="token punctuation">,</span>saddress<span class="token punctuation">)</span> <span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token string">'张三'</span><span class="token punctuation">,</span><span class="token number">23</span><span class="token punctuation">,</span><span class="token string">'111'</span><span class="token punctuation">,</span><span class="token string">'河北石家庄枣各庄'</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2-3-2、新建POJO类（Table映射实体类）"><a href="#2-3-2、新建POJO类（Table映射实体类）" class="headerlink" title="2.3.2、新建POJO类（Table映射实体类）"></a>2.3.2、新建POJO类（Table映射实体类）</h3><p>​    为便于后期实现**<code>JSON</code><strong>数据格式转换，</strong><code>POJO（Model、JavaBean）</code><strong>类要求实现序列化接口</strong><code>Serializable</code>**</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SsmTest01</span> <span class="token keyword">implements</span> <span class="token class-name">Serializable</span><span class="token punctuation">&#123;</span>
	<span class="token keyword">private</span> <span class="token class-name">Integer</span> sid<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">String</span> sname<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">Integer</span> sage<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">String</span> spassword<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">String</span> saddress<span class="token punctuation">;</span>
  
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token keyword">return</span> <span class="token string">"SsmTest01 [sid="</span> <span class="token operator">+</span> sid <span class="token operator">+</span> <span class="token string">", sname="</span> <span class="token operator">+</span> sname <span class="token operator">+</span> <span class="token string">", sage="</span> <span class="token operator">+</span> sage <span class="token operator">+</span> <span class="token string">", spassword="</span> <span class="token operator">+</span> spassword
				<span class="token operator">+</span> <span class="token string">", saddress="</span> <span class="token operator">+</span> saddress <span class="token operator">+</span> <span class="token string">"]"</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token class-name">SsmTest01</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token class-name">SsmTest01</span><span class="token punctuation">(</span><span class="token class-name">Integer</span> sid<span class="token punctuation">,</span> <span class="token class-name">String</span> sname<span class="token punctuation">,</span> <span class="token class-name">Integer</span> sage<span class="token punctuation">,</span> <span class="token class-name">String</span> spassword<span class="token punctuation">,</span> <span class="token class-name">String</span> saddress<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>sid <span class="token operator">=</span> sid<span class="token punctuation">;</span><span class="token keyword">this</span><span class="token punctuation">.</span>sname <span class="token operator">=</span> sname<span class="token punctuation">;</span><span class="token keyword">this</span><span class="token punctuation">.</span>sage <span class="token operator">=</span> sage<span class="token punctuation">;</span><span class="token keyword">this</span><span class="token punctuation">.</span>spassword <span class="token operator">=</span> spassword<span class="token punctuation">;</span><span class="token keyword">this</span><span class="token punctuation">.</span>saddress <span class="token operator">=</span> saddress<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token class-name">Integer</span> <span class="token function">getSid</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">return</span> sid<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setSid</span><span class="token punctuation">(</span><span class="token class-name">Integer</span> sid<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">this</span><span class="token punctuation">.</span>sid <span class="token operator">=</span> sid<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getSname</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">return</span> sname<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setSname</span><span class="token punctuation">(</span><span class="token class-name">String</span> sname<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">this</span><span class="token punctuation">.</span>sname <span class="token operator">=</span> sname<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token class-name">Integer</span> <span class="token function">getSage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">return</span> sage<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setSage</span><span class="token punctuation">(</span><span class="token class-name">Integer</span> sage<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">this</span><span class="token punctuation">.</span>sage <span class="token operator">=</span> sage<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getSpassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">return</span> spassword<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setSpassword</span><span class="token punctuation">(</span><span class="token class-name">String</span> spassword<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">this</span><span class="token punctuation">.</span>spassword <span class="token operator">=</span> spassword<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getSaddress</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">return</span> saddress<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setSaddress</span><span class="token punctuation">(</span><span class="token class-name">String</span> saddress<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span><span class="token keyword">this</span><span class="token punctuation">.</span>saddress <span class="token operator">=</span> saddress<span class="token punctuation">;</span><span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2-3-3、引入MyBatis依赖"><a href="#2-3-3、引入MyBatis依赖" class="headerlink" title="2.3.3、引入MyBatis依赖"></a>2.3.3、引入MyBatis依赖</h3><ol>
<li>引入**<code>MyBatis</code>**核心依赖。</li>
<li>引入**<code>MyBatis</code>**分页插件依赖。</li>
<li>引入**<code>MySQL</code>**数据库驱动、连接池。</li>
<li>引入**<code>Log4J</code>**日志支持依赖。</li>
</ol>
<p>​    在仓库搜索**<code>MyBatis、Log4j、MySQL</code><strong>等，修改</strong><code>pom.xml</code><strong>核心配置文件引入依赖</strong><code>3.4.6</code>**版本（该依赖，会自动导入其他依赖）。当然如果不愿意，也可以自己一个一个的引入。</p>
<blockquote>
</blockquote>
<p><img src="../SSM%E6%95%B4%E5%90%884S%E6%B1%BD%E8%BD%A6%E5%BA%97CRM//SSM%E6%95%B4%E5%90%88/6%E3%80%81MyBatis%E4%BE%9D%E8%B5%96.png" alt="MyBatis依赖"></p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- #######################  MyBatis   ####################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.mybatis<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>mybatis<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>3.4.6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- #######################  MyBatis分页插件    #################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>com.github.pagehelper<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>pagehelper<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>5.1.10<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- ######################  MySQL驱动   ##################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>mysql<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>mysql-connector-java<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>5.1.47<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- #######################  druid连接池    #################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/com.alibaba/druid --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>com.alibaba<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>druid<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.1.22<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- c3p0 https://mvnrepository.com/artifact/com.mchange/c3p0 
    &lt;dependency>
        &lt;groupId>com.mchange&lt;/groupId>
        &lt;artifactId>c3p0&lt;/artifactId>
        &lt;version>0.9.5.2&lt;/version>
    &lt;/dependency>
    --></span>

<span class="token comment">&lt;!-- #######################  Log4j日志    #################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/log4j/log4j --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>log4j<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>log4j<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.2.17<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.slf4j<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>slf4j-api<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.7.25<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.slf4j<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>slf4j-log4j12<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.7.25<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-3-4、配置Log4j日志属性文件"><a href="#2-3-4、配置Log4j日志属性文件" class="headerlink" title="2.3.4、配置Log4j日志属性文件"></a>2.3.4、配置Log4j日志属性文件</h3><p>​    日志配置文件信息概述更多介绍请自行查阅资料。</p>
<pre class="line-numbers language-properties" data-language="properties"><code class="language-properties"><span class="token comment">################################################################</span>
<span class="token comment">##### 日志输出类别和级别																		   #####</span>
<span class="token comment">##### 其中 [ level ] 是日志输出级别：ERROR、WARN、INFO、DEBUG   #####</span>
<span class="token comment">##### ERROR 为严重错误 主要是程序的错误												 #####	</span>
<span class="token comment">##### WARN 为一般警告，比如session丢失												 #####</span>
<span class="token comment">##### INFO 为一般要显示的信息，比如登录登出										   #####</span>
<span class="token comment">##### DEBUG 为程序的调试信息（常用）														#####</span>
<span class="token comment">################################################################</span>
<span class="token key attr-name">log4j.rootLogger</span><span class="token punctuation">=</span><span class="token value attr-value">debug,stdout</span>

<span class="token comment">### 配置输出到控制台 ###</span>
<span class="token key attr-name">log4j.appender.stdout</span><span class="token punctuation">=</span><span class="token value attr-value">org.apache.log4j.ConsoleAppender</span>
<span class="token comment">#log4j.appender.stdout.Target=System.err</span>
<span class="token key attr-name">log4j.appender.stdout.layout</span><span class="token punctuation">=</span><span class="token value attr-value">org.apache.log4j.SimpleLayout</span>
<span class="token comment">### 配置输出到文件 ###</span>
<span class="token comment">#log4j.appender.logfile=org.apache.log4j.FileAppender</span>
<span class="token comment">#log4j.appender.logfile.File=jbit.log</span>
<span class="token comment">#log4j.appender.logfile.layout=org.apache.log4j.PatternLayout</span>
<span class="token comment">#log4j.appender.logfile.layout.ConversionPattern=%d&#123;yyyy-MM-dd HH:mm:ss&#125; %F %p %m%n</span>

<span class="token comment">### 设置输出sql的级别，其中logger后面的内容全部为jar包中所包含的包名 ###</span>
<span class="token key attr-name">log4j.logger.com.ibatis</span><span class="token punctuation">=</span><span class="token value attr-value">DEBUG</span>
<span class="token key attr-name">log4j.logger.com.ibatis.common.jdbc.SimpleDataSource</span><span class="token punctuation">=</span><span class="token value attr-value">DEBUG</span>
<span class="token key attr-name">log4j.logger.com.ibatis.common.jdbc.ScriptRunner</span><span class="token punctuation">=</span><span class="token value attr-value">DEBUG</span>
<span class="token key attr-name">log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate</span><span class="token punctuation">=</span><span class="token value attr-value">DEBUG</span>
<span class="token key attr-name">log4j.logger.java.sql.Connection</span><span class="token punctuation">=</span><span class="token value attr-value">DEBUG</span>
<span class="token key attr-name">log4j.logger.java.sql.Statement</span><span class="token punctuation">=</span><span class="token value attr-value">DEBUG</span>
<span class="token key attr-name">log4j.logger.java.sql.PreparedStatement</span><span class="token punctuation">=</span><span class="token value attr-value">DEBUG</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-3-5、新建MyBatis核心配置文件"><a href="#2-3-5、新建MyBatis核心配置文件" class="headerlink" title="2.3.5、新建MyBatis核心配置文件"></a>2.3.5、新建MyBatis核心配置文件</h3><p>​    在资源目录下新增**<code>mybatis-config.xml</code>**核心配置文件。</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8" ?></span>
<span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">configuration</span>
        <span class="token name">PUBLIC</span> <span class="token string">"-//mybatis.org//DTD Config 3.0//EN"</span>
        <span class="token string">"http://mybatis.org/dtd/mybatis-3-config.dtd"</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>configuration</span><span class="token punctuation">></span></span>
	
    <span class="token comment">&lt;!-- 开启驼峰命名规则 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>settings</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>setting</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>mapUnderscoreToCamelCase<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>true<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>settings</span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!-- 开启批量定义类型别名 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>typeAliases</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>package</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm.bean<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>typeAliases</span><span class="token punctuation">></span></span>

    <span class="token comment">&lt;!-- environments：MyBatis环境配置标签。属性default，表示默认选择哪个开发环境（值为数据源ID值） --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>environments</span> <span class="token attr-name">default</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>mysql<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token comment">&lt;!-- 配置开发环境，可以存在多个环境，属性ID：环境的唯一名字【任意】。 --></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>environment</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>mysql<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
            <span class="token comment">&lt;!-- transactionManager：配置事务标签。type值设定JDBC，表示使用JDBC事务管理 --></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>transactionManager</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>JDBC<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
            <span class="token comment">&lt;!-- 配置数据源，POOLED表示使用连接池链接数据源 --></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dataSource</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>POOLED<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
               <span class="token comment">&lt;!-- 配置数据源信息 --></span>
               <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>driver<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.mysql.jdbc.Driver<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
               <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>url<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>jdbc:mysql://localhost:3306/ssm01<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
               <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>username<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>root<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
               <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>root<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dataSource</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>environment</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>environments</span><span class="token punctuation">></span></span>
    	
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mappers</span><span class="token punctuation">></span></span>
	    <span class="token comment">&lt;!--注册指定包下所有的mapper映射文件--></span>
	    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>package</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm.dao<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mappers</span><span class="token punctuation">></span></span>
    
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>configuration</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-3-6、编写MyBatis持久层工具类"><a href="#2-3-6、编写MyBatis持久层工具类" class="headerlink" title="2.3.6、编写MyBatis持久层工具类"></a>2.3.6、编写MyBatis持久层工具类</h3><p>​    当前搭建引入的是**<code>MyBatis</code><strong>环境，为便于</strong><code>CRUD</code>**测试，建议提供工具类！（省略亦可）</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyBatisUtils</span> <span class="token punctuation">&#123;</span>
	    <span class="token comment">/**
     * 获取SQL会话工厂
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">SqlSessionFactory</span> <span class="token function">getSqlSessionFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token class-name">InputStream</span> inputStream <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
		<span class="token keyword">try</span> <span class="token punctuation">&#123;</span>
			inputStream <span class="token operator">=</span> <span class="token class-name">Resources</span><span class="token punctuation">.</span><span class="token function">getResourceAsStream</span><span class="token punctuation">(</span><span class="token string">"mybatis-config.xml"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">&#125;</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">IOException</span> e<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
			<span class="token comment">// TODO Auto-generated catch block</span>
			e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">&#125;</span>
        <span class="token class-name">SqlSessionFactory</span> sessionFactory <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SqlSessionFactoryBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span>inputStream<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> sessionFactory<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-3-7编写Mapper（DAO）接口"><a href="#2-3-7编写Mapper（DAO）接口" class="headerlink" title="2.3.7编写Mapper（DAO）接口"></a>2.3.7编写Mapper（DAO）接口</h3><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">SsmTest01Dao</span> <span class="token punctuation">&#123;</span>
	<span class="token comment">/**
	 * 查询所有
	 */</span>
	<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SsmTest01</span><span class="token punctuation">></span></span> <span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-3-8、新增Mapper接口映射"><a href="#2-3-8、新增Mapper接口映射" class="headerlink" title="2.3.8、新增Mapper接口映射"></a>2.3.8、新增Mapper接口映射</h3><p>​    在**<code>DAO</code><strong>层根目录新建</strong><code>Mapper</code>**接口映射。</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8" ?></span>
<span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">mapper</span>
        <span class="token name">PUBLIC</span> <span class="token string">"-//mybatis.org//DTD Mapper 3.0//EN"</span>
        <span class="token string">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"</span><span class="token punctuation">></span></span>
<span class="token comment">&lt;!--命名空间名称与Mapper接口名称一致--></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mapper</span> <span class="token attr-name">namespace</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm.dao.SsmTest01Dao<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 查询所有 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>select</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>findList<span class="token punctuation">"</span></span> <span class="token attr-name">resultType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>ssmTest01<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
         select * from ssmtest01
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>select</span><span class="token punctuation">></span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mapper</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
<p>[^要求]: </p>
<ol>
<li>Mapper接口映射==文件名必须与==Mapper==接口名相同==。</li>
<li>Mapper接口映射文件==必须与Mapper接口类文件在同一个目录中==。</li>
<li>Mapper接口映射中==namespace命名空间名必须是对应Mapper接口类全限定名==。</li>
<li>==必须在MyBatis核心配置文件中引入Mapper映射==。</li>
</ol>
</blockquote>
<h3 id="2-3-9、编写Service接口"><a href="#2-3-9、编写Service接口" class="headerlink" title="2.3.9、编写Service接口"></a>2.3.9、编写Service接口</h3><p>​    业务层接口通常与持久层一致</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">SsmTest01Service</span> <span class="token punctuation">&#123;</span>
	<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SsmTest01</span><span class="token punctuation">></span></span> <span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>

<h3 id="2-3-10、新增Service接口实现"><a href="#2-3-10、新增Service接口实现" class="headerlink" title="2.3.10、新增Service接口实现"></a>2.3.10、新增Service接口实现</h3><p>​    在**<code>Service</code><strong>接口实现类中，调用</strong><code>DAO</code>**层方法，测试/实现功能</p>
<ol>
<li>读取**<code>MyBatis</code>**核心配置文件。</li>
<li>创建**<code>SQL</code><strong>会话工厂生成器</strong><code>SqlSessionFactoryBuilder</code><strong>，生成</strong><code>SQL</code><strong>会话工厂</strong><code>SqlSessionFactory</code>**。</li>
<li>获取**<code>SQL</code><strong>会话对象</strong><code>SqlSession</code>**。</li>
<li>获取**<code>Mapper</code>**接口代理对象。</li>
<li>调用**<code>Mapper</code>**接口方法执行。</li>
</ol>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SsmTest01ServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">SsmTest01Service</span> <span class="token punctuation">&#123;</span>
	<span class="token comment">/**
	 * 查询所有
	 * @throws IOException 
	 */</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SsmTest01</span><span class="token punctuation">></span></span> <span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// 读取核心配置文件</span>
		<span class="token comment">// InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");</span>
		<span class="token comment">// 创建SQL会话工厂生成器，生成SQL会话工厂对象</span>
		<span class="token comment">// SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);</span>
		
		<span class="token comment">// 使用工具类获取SqlSessionFactory</span>
		<span class="token class-name">SqlSessionFactory</span> sessionFactory  <span class="token operator">=</span> <span class="token class-name">MyBatisUtils</span><span class="token punctuation">.</span><span class="token function">getSqlSessionFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 获取sqlSession会话</span>
		<span class="token class-name">SqlSession</span> sqlSession <span class="token operator">=</span> sessionFactory<span class="token punctuation">.</span><span class="token function">openSession</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 获取Mapper接口代理对象</span>
		<span class="token class-name">SsmTest01Dao</span> ssmMapper <span class="token operator">=</span> sqlSession<span class="token punctuation">.</span><span class="token function">getMapper</span><span class="token punctuation">(</span><span class="token class-name">SsmTest01Dao</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>	
		<span class="token keyword">return</span> ssmMapper<span class="token punctuation">.</span><span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-3-11、在控制器中添加测试调用"><a href="#2-3-11、在控制器中添加测试调用" class="headerlink" title="2.3.11、在控制器中添加测试调用"></a>2.3.11、在控制器中添加测试调用</h3><p>​    在控制器**<code>Controller</code><strong>中添加方法，测试调用</strong><code>MyBatis</code>**持久层操作数据库实现查询。</p>
<ol>
<li>新建**<code>Service</code>**实现类对象。</li>
<li>调用**<code>Service</code>**查询方法。</li>
<li>将查询结果通过**<code>Model</code>**对象发送至页面</li>
</ol>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token annotation punctuation">@Controller</span>
<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/test"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ControllerTest</span> <span class="token punctuation">&#123;</span>
	<span class="token comment">/**
	 * Controller测试SrpingMVC环境
	 **/</span>
	<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/springMVCTest"</span><span class="token punctuation">)</span>
	 <span class="token comment">// @ResponseBody 测试JSON</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">springMVCTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"springMVCTest测试Spring MVC环境"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token string">"springMVCTest"</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
	
	<span class="token comment">/**
	 * 请求测试查询所有
	 */</span>
	<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/list"</span><span class="token punctuation">)</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">findList</span><span class="token punctuation">(</span><span class="token class-name">Model</span> model<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// 新建service实现实例</span>
		<span class="token class-name">SsmTest01Service</span> ssmTest01ServiceImpl <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SsmTest01ServiceImpl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 调用方法获取查询所有</span>
		<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SsmTest01</span><span class="token punctuation">></span></span> listSsmTest <span class="token operator">=</span> ssmTest01ServiceImpl<span class="token punctuation">.</span><span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 通过Model将数据结果发送到页面（保存在request域对象中）</span>
		model<span class="token punctuation">.</span><span class="token function">addAttribute</span><span class="token punctuation">(</span><span class="token string">"listSsmTest"</span><span class="token punctuation">,</span> listSsmTest<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token string">"list"</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2-3-12、编写跳转页面（显示查询结果）"><a href="#2-3-12、编写跳转页面（显示查询结果）" class="headerlink" title="2.3.12、编写跳转页面（显示查询结果）"></a>2.3.12、编写跳转页面（显示查询结果）</h3><pre class="line-numbers language-markup" data-language="markup"><code class="language-markup">&lt;%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<span class="token comment">&lt;!-- 导入JSTL-C标签库 --></span>
&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>UTF-8<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">></span></span>Insert title here<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
	
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tbody</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>用户ID<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>账户名<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>登录密码<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>用户年龄<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>注册地址<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>其他操作<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span class="token punctuation">></span></span>
      <span class="token comment">&lt;!-- 获取Model中存储的数据，并遍历显示 --></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">c:</span>forEach</span> <span class="token attr-name">var</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>ssmtest<span class="token punctuation">"</span></span> <span class="token attr-name">items</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>$&#123;listSsmTest &#125;<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span class="token punctuation">></span></span>
					<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>$&#123;ssmtest.sid &#125;<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
					<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>$&#123;ssmtest.sname &#125;<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
					<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>$&#123;ssmtest.spassword&#125;<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
					<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>$&#123;ssmtest.sage &#125;<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
					<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>$&#123;ssmtest.saddress &#125;<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
					<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>
						<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>#<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>修改<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">></span></span>
						<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>#<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>删除<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">></span></span>
					<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
				<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span class="token punctuation">></span></span>
			<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">c:</span>forEach</span><span class="token punctuation">></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tbody</span><span class="token punctuation">></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span class="token punctuation">></span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>任务：搭建**<code>MyBatis、Spring MVC</code><strong>环境完成</strong><code>CURD</code>**（登录，注册，查询所有，条件组合查询，删除，更新）</p>
<h2 id="2-4、整合之加入Spring环境"><a href="#2-4、整合之加入Spring环境" class="headerlink" title="2.4、整合之加入Spring环境"></a>2.4、整合之加入Spring环境</h2><p>​    **<code>Spring</code><strong>分工：负责整个</strong><code>WEB</code>**各个层次间所有对象的初始化，以及业务层事务处理。</p>
<h3 id="2-4-1、引入Spring依赖jar"><a href="#2-4-1、引入Spring依赖jar" class="headerlink" title="2.4.1、引入Spring依赖jar"></a>2.4.1、引入Spring依赖jar</h3><p>​    <strong><code>Spring MVC</code><strong>是</strong><code>Spring</code><strong>中的一个子项目，前面已经基本引入了</strong><code>Spring</code><strong>的所有依赖，这里还需要加入</strong><code>Spring</code><strong>事务处理、和面向切面的依赖。搜索：</strong><code>spring-jdbc（自动引入事务tx其他依赖）、spring-aspects（自动引入其他依赖）</code></strong></p>
<p><img src="/SSM%E6%95%B4%E5%90%88/7%E3%80%81Spring%E4%BA%8B%E5%8A%A1%E4%B8%8E%E9%9D%A2%E5%90%91%E5%88%87%E9%9D%A2%E4%BE%9D%E8%B5%96.png" alt="Spring事务与面向切面"></p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- #######################  Spring面向切面   ###################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-aspects<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>5.2.5.RELEASE<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- #######################  Spring事务处理   ###################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-jdbc<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>5.2.5.RELEASE<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2-4-2、Spring整合Spring-MVC"><a href="#2-4-2、Spring整合Spring-MVC" class="headerlink" title="2.4.2、Spring整合Spring MVC"></a>2.4.2、Spring整合Spring MVC</h3><p>​    整合**<code>Spring、Spring MVC</code><strong>，实现对象初始化完全由</strong><code>Spring</code><strong>管理。</strong><code>Spring MVC</code><strong>是</strong><code>Spring</code>**中的一个子项目，二者之间可以无缝结合无需第三方依赖整合。</p>
<p>​    程序中，控制器**<code>Controller</code><strong>层在调用业务层</strong><code>Service</code><strong>方法时，需要创建业务层</strong><code>Service</code><strong>实现类对象，将该对象的初始化实现交由</strong><code>Spring</code>**管理。</p>
<ol>
<li>编写**<code>Spring</code><strong>核心配置文件</strong><code>applicationContext.xml</code>**。</li>
<li>开启**<code>Spring</code>**注解组件扫描。</li>
<li>在业务层类上添加**<code>@Service</code>**组件注解。</li>
<li>在控制器层声明业务层属性并使用**<code>@Autowired</code>**注解。（完成自动注入）</li>
<li>修改**<code>web.xml</code><strong>配置启动加载</strong><code>Spring</code>**核心配置文件（容器）。</li>
</ol>
<p>核心配置文件</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>beans</span> <span class="token attr-name">xmlns</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/beans<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>context</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/context<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>aop</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/aop<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>tx</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/tx<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xsi:</span>schemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 将各层级对象的初始化交由Spring管理，开启并使用Spring注解 --></span>
	<span class="token comment">&lt;!-- 开启组件注解扫描：Repository（持久层）、Service、Controller --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">context:</span>component-scan</span> <span class="token attr-name">base-package</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm.*<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置除了Controller的注解，其他组件注解都扫描 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">context:</span>exclude-filter</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>annotation<span class="token punctuation">"</span></span> <span class="token attr-name">expression</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.springframework.stereotype.Controller<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">context:</span>component-scan</span><span class="token punctuation">></span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>beans</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>业务层添加注解组件</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SsmTest01ServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">SsmTest01Service</span> <span class="token punctuation">&#123;</span>
	
	<span class="token comment">/**
	 * 查询所有
	 * @throws IOException 
	 */</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SsmTest01</span><span class="token punctuation">></span></span> <span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// 读取核心配置文件</span>
		<span class="token comment">// InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");</span>
		<span class="token comment">// 创建SQL会话工厂生成器，生成SQL会话工厂对象</span>
		<span class="token comment">// SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);</span>
		
		<span class="token comment">// 使用工具类获取SqlSessionFactory</span>
		<span class="token class-name">SqlSessionFactory</span> sessionFactory  <span class="token operator">=</span> <span class="token class-name">MyBatisUtils</span><span class="token punctuation">.</span><span class="token function">getSqlSessionFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 获取sqlSession会话</span>
		<span class="token class-name">SqlSession</span> sqlSession <span class="token operator">=</span> sessionFactory<span class="token punctuation">.</span><span class="token function">openSession</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 获取Mapper接口代理对象</span>
		<span class="token class-name">SsmTest01Dao</span> ssmMapper <span class="token operator">=</span> sqlSession<span class="token punctuation">.</span><span class="token function">getMapper</span><span class="token punctuation">(</span><span class="token class-name">SsmTest01Dao</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>	
		<span class="token keyword">return</span> ssmMapper<span class="token punctuation">.</span><span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>控制器声明**<code>Service</code>**属性注入</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token annotation punctuation">@Controller</span>
<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/test"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ControllerTest</span> <span class="token punctuation">&#123;</span>
	
	<span class="token annotation punctuation">@Autowired</span> <span class="token comment">// 自动注入</span>
	<span class="token keyword">private</span> <span class="token class-name">SsmTest01Service</span> ssmTest01ServiceImpl<span class="token punctuation">;</span>
	<span class="token comment">/**
	 * Controller测试SrpingMVC环境
	 **/</span>
	<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/springMVCTest"</span><span class="token punctuation">)</span>
	 <span class="token comment">// @ResponseBody 测试JSON</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">springMVCTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"springMVCTest测试Spring MVC环境"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token string">"springMVCTest"</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
	
	<span class="token comment">/**
	 * 请求测试查询所有
	 */</span>
	<span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/list"</span><span class="token punctuation">)</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">findList</span><span class="token punctuation">(</span><span class="token class-name">Model</span> model<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// 新建service实现实例</span>
		<span class="token comment">// SsmTest01Service ssmTest01ServiceImpl = new SsmTest01ServiceImpl();</span>
		<span class="token comment">// 调用方法获取查询所有</span>
		<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SsmTest01</span><span class="token punctuation">></span></span> listSsmTest <span class="token operator">=</span> ssmTest01ServiceImpl<span class="token punctuation">.</span><span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 通过Model将数据结果发送到页面（保存在request域对象中）</span>
		model<span class="token punctuation">.</span><span class="token function">addAttribute</span><span class="token punctuation">(</span><span class="token string">"listSsmTest"</span><span class="token punctuation">,</span> listSsmTest<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token string">"list"</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<p>修改**<code>web.xml</code><strong>启动</strong><code>Spring</code>**容器</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>web-app</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>WebApp_ID<span class="token punctuation">"</span></span> <span class="token attr-name">version</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>3.1<span class="token punctuation">"</span></span> <span class="token attr-name">xmlns</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://xmlns.jcp.org/xml/ns/javaee<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">xsi:</span>schemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!--++++++++ 配置启动Spring容器 ++++++++--></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>listener</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>listener-class</span><span class="token punctuation">></span></span>org.springframework.web.context.ContextLoaderListener<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>listener-class</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>listener</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>context-param</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>contextConfigLocation<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>classpath:applicationContext.xml<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>context-param</span><span class="token punctuation">></span></span>

    <span class="token comment">&lt;!-- ++++++++ Spring MVC核心配置：前端控制器Servlet ++++++ --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>dispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-class</span><span class="token punctuation">></span></span>org.springframework.web.servlet.DispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-class</span><span class="token punctuation">></span></span>
        <span class="token comment">&lt;!-- 配置加载Spring MVC核心配置文件 --></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>contextConfigLocation<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>classpath:spring-mvc.xml<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>
        <span class="token comment">&lt;!-- 配置服务器启动时立即加载 --></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>load-on-startup</span><span class="token punctuation">></span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>load-on-startup</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet</span><span class="token punctuation">></span></span>
	
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-mapping</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>dispatcherServlet<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-mapping</span><span class="token punctuation">></span></span>

    <span class="token comment">&lt;!-- ++++++++配置Spring MVC核心编码处理拦截器+++++++++ --></span>
  	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>characterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-class</span><span class="token punctuation">></span></span>org.springframework.web.filter.CharacterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-class</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>  
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>encoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>  
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>UTF-8<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>  
        <span class="token comment">&lt;!-- 配置是否开启请求编码处理 --></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>  
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>forceRequestEncoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>  
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>  
        <span class="token comment">&lt;!-- 配置是否开启响应编码处理 --></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>init-param</span><span class="token punctuation">></span></span>  
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-name</span><span class="token punctuation">></span></span>forceResponseEncoding<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-name</span><span class="token punctuation">></span></span>  
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>param-value</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>param-value</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>init-param</span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-mapping</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>characterEncodingFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>  
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/*<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-mapping</span><span class="token punctuation">></span></span> 

    <span class="token comment">&lt;!-- 配置支持RESTFUL风格的多种请求方式的过滤器 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>HiddenHttpMethodFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-class</span><span class="token punctuation">></span></span>org.springframework.web.filter.HiddenHttpMethodFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-class</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-mapping</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>filter-name</span><span class="token punctuation">></span></span>HiddenHttpMethodFilter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-name</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>/*<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>filter-mapping</span><span class="token punctuation">></span></span>
	
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>welcome-file-list</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>welcome-file</span><span class="token punctuation">></span></span>index.jsp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>welcome-file</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>welcome-file-list</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>web-app</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2-4-3、启动测试"><a href="#2-4-3、启动测试" class="headerlink" title="2.4.3、启动测试"></a>2.4.3、启动测试</h3><p>​    略……（整合**<code>Spring、Spring MVC</code>**完结！）</p>
<h2 id="2-5、Spring整合MyBatis"><a href="#2-5、Spring整合MyBatis" class="headerlink" title="2.5、Spring整合MyBatis"></a>2.5、Spring整合MyBatis</h2><p>​    **<code>Spring</code><strong>整合</strong><code>MyBatis</code><strong>需要第三方整合依赖</strong><code>MyBatis-Spring.jar</code><strong>，当</strong><code>Service</code><strong>需要使用</strong><code>Mapper（DAO）</code><strong>对象时，由</strong><code>Spring</code>**管理并注入。</p>
<h3 id="2-5-1、引入第三方整合依赖jar"><a href="#2-5-1、引入第三方整合依赖jar" class="headerlink" title="2.5.1、引入第三方整合依赖jar"></a>2.5.1、引入第三方整合依赖jar</h3><pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- #######################  Spring整合MyBatis   ###################### --></span>
<span class="token comment">&lt;!--MyBatis-Spring整合第三方依赖 https://mvnrepository.com/artifact/org.mybatis/mybatis-spring --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.mybatis<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>mybatis-spring<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.3.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>​        整合前：（**<code>Service</code><strong>操作</strong><code>Mapper</code>**）</p>
<ol>
<li><p>读取**<code>MyBatis</code><strong>核心配置文件，（配置数据源，引入</strong><code>Mapper</code>**接口映射）。</p>
</li>
<li><p>创建**<code>SqlSessionFactoryBuilder</code>**。</p>
</li>
<li><p>获取**<code>SqlSessionFactory</code>**。</p>
</li>
<li><p>获取**<code>SqlSession</code>**。</p>
</li>
<li><p>获取**<code>Mapper</code>**接口代理对象。</p>
<p>整合后：（**<code>Service</code><strong>操作</strong><code>Mapper</code>**）</p>
</li>
</ol>
<p>​    思想：将所有对象的初始化都交由**<code>Spring</code><strong>管理。如会：话工厂对象，</strong><code>Mapper</code>**接口代理对象。</p>
<h3 id="2-5-2、新建数据源属性配置文件Pproperties"><a href="#2-5-2、新建数据源属性配置文件Pproperties" class="headerlink" title="2.5.2、新建数据源属性配置文件Pproperties"></a>2.5.2、新建数据源属性配置文件Pproperties</h3><p>​    在资源根目录（或**<code>src</code><strong>目录）下，新建“</strong><code>xxx.properties</code>**”属性配置文件，配置连接参数及连接池参数。</p>
<pre class="line-numbers language-properties" data-language="properties"><code class="language-properties"><span class="token key attr-name">jdbc.driverClassName</span><span class="token punctuation">=</span><span class="token value attr-value">com.mysql.jdbc.Driver</span>
<span class="token key attr-name">jdbc.jdbcUrl</span><span class="token punctuation">=</span><span class="token value attr-value">jdbc:mysql://localhost:3306/ssm01</span>
<span class="token key attr-name">jdbc.username</span><span class="token punctuation">=</span><span class="token value attr-value">root</span>
<span class="token key attr-name">jdbc.password</span><span class="token punctuation">=</span><span class="token value attr-value">root</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-5-3、修改Spring核心配置文件迁移数据源配置信息"><a href="#2-5-3、修改Spring核心配置文件迁移数据源配置信息" class="headerlink" title="2.5.3、修改Spring核心配置文件迁移数据源配置信息"></a>2.5.3、修改Spring核心配置文件迁移数据源配置信息</h3><p>​    **<code>MyBatis</code><strong>操作</strong><code>DAO</code><strong>的程序中，需要使用</strong><code>SqlSessionFactoryBuilder</code><strong>创建</strong><code>SqlSessionFactory</code><strong>，再用</strong><code>SqlSessionFactory</code><strong>获取</strong><code>SqlSession</code>**，前提是需要加载核心配置文件中的数据源信息。</p>
<p>​    将对象的初始化交由**<code>Spring</code><strong>管理，然而这些对象的使用，必须依赖于数据源配置信息，</strong><code>Spring</code><strong>不可能去攻击</strong><code>MyBatis</code><strong>框架，读取</strong><code>MyBatis</code><strong>框架中配置的资源。那么最好的解决方案就是将数据源配置信息一同迁移至</strong><code>Spring</code>**框架中。</p>
<ol>
<li>引入外部属性配置文件</li>
<li>配置数据源（连接池）</li>
<li>配置第三方整合提供的**<code>SqlSessionFactoryBean</code><strong>生成</strong><code>SqlSessionFactory</code><strong>（交由</strong><code>Spring</code>**管理）</li>
<li>配置第三方整合提供的**<code>Mapper</code><strong>接口扫描器</strong><code>MapperScannerConfigurer</code><strong>，实现</strong><code>Mapper</code><strong>接口、</strong><code>Mapper</code><strong>映射文件的扫描（说明：</strong><code>Mapper</code><strong>接口代理对象也由该配置生成并放入到</strong><code>IOC</code><strong>容器中——交由</strong><code>Spring</code>**管理）。</li>
</ol>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token prolog">&lt;?xml version="1.0" encoding="UTF-8"?></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>beans</span> <span class="token attr-name">xmlns</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/beans<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>xsi</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>context</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/context<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>aop</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/aop<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xmlns:</span>tx</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/tx<span class="token punctuation">"</span></span>
	<span class="token attr-name"><span class="token namespace">xsi:</span>schemaLocation</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx.xsd<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 将各层级对象的初始化交由Spring管理，开启并使用Spring注解 --></span>
	<span class="token comment">&lt;!-- 开启组件注解扫描：Repository（持久层）、Service（业务层）、Controller（控制层） --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">context:</span>component-scan</span> <span class="token attr-name">base-package</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm.*<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置除了Controller的注解，其他组件注解都扫描 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">context:</span>exclude-filter</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>annotation<span class="token punctuation">"</span></span> <span class="token attr-name">expression</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.springframework.stereotype.Controller<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">context:</span>component-scan</span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 1.============引入外部数据源属性文件 --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">context:</span>property-placeholder</span> <span class="token attr-name">location</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>classpath:druidDB.properties<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
	
	<span class="token comment">&lt;!-- 2.============配置数据源（连接池）：Druid连接池数据源使用的类是DruidDataSource --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>dataSource<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.alibaba.druid.pool.DruidDataSource<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 配置数据库连接参数：这里使用的是Druid连接池：不同连接池属性名不同，可自行查阅官网文档 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>driverClassName<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>$&#123;jdbc.driverClassName&#125;<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>url<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>$&#123;jdbc.jdbcUrl&#125;<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>username<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>$&#123;jdbc.username&#125;<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>$&#123;jdbc.password&#125;<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
		
		<span class="token comment">&lt;!-- 连接池参数：最大连接数 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>maxActive<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>20<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
		<span class="token comment">&lt;!-- 连接池参数：初始化创建 --></span>	
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>initialSize<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>5<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bean</span><span class="token punctuation">></span></span>	
	
	<span class="token comment">&lt;!-- 3.============使用第三方整合依赖提供的SqlSessionFactoryBean,生成sqlSessionFactory--></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>sqlSessionFactory<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.mybatis.spring.SqlSessionFactoryBean<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 注入属性dataSource：指定数据源 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>dataSource<span class="token punctuation">"</span></span> <span class="token attr-name">ref</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>dataSource<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
		<span class="token comment">&lt;!-- 注入属性configLocation：配置MyBatis核心配置文件地址 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>configLocation<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>classpath:mybatis-config.xml<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bean</span><span class="token punctuation">></span></span>
	
	<span class="token comment">&lt;!-- 4.===========配置Mapper接口扫描器，将Mapper接口代理对象交由Spring管理 --></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.mybatis.spring.mapper.MapperScannerConfigurer<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
		<span class="token comment">&lt;!-- 注入属性basePackage：配置Mapper接口所在包 --></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>basePackage<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm.dao<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bean</span><span class="token punctuation">></span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>beans</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="2-5-4、修改Service业务层代码，使用Spring注解注入Mapper对象"><a href="#2-5-4、修改Service业务层代码，使用Spring注解注入Mapper对象" class="headerlink" title="2.5.4、修改Service业务层代码，使用Spring注解注入Mapper对象"></a>2.5.4、修改Service业务层代码，使用Spring注解注入Mapper对象</h3><pre class="line-numbers language-java" data-language="java"><code class="language-java">
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SsmTest01ServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">SsmTest01Service</span> <span class="token punctuation">&#123;</span>
	<span class="token comment">// 属性自动注入Mapper接口代理对象（Spring管理实现）</span>
	<span class="token annotation punctuation">@Autowired</span>
	<span class="token keyword">private</span> <span class="token class-name">SsmTest01Dao</span> ssmMapper<span class="token punctuation">;</span>
	
	<span class="token comment">/**
	 * 查询所有
	 * @throws IOException 
	 */</span>
	<span class="token annotation punctuation">@Override</span>
	<span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">SsmTest01</span><span class="token punctuation">></span></span> <span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// 使用SSM整合Mapper接口代理对象调用方法</span>
		<span class="token keyword">return</span> ssmMapper<span class="token punctuation">.</span><span class="token function">findList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2-5-5、整合测试"><a href="#2-5-5、整合测试" class="headerlink" title="2.5.5、整合测试"></a>2.5.5、整合测试</h3><p>​    启动服务访问查询验证略…………</p>
<h3 id="2-5-6、常见错误问题"><a href="#2-5-6、常见错误问题" class="headerlink" title="2.5.6、常见错误问题"></a>2.5.6、常见错误问题</h3><ol>
<li>**<code>SSM</code>**整合    **<code>Spring MVC</code><strong>与</strong><code>Spring</code>**版本要一直，不同版本之间可能出现不同的兼容问题。</li>
<li>如果确认整个项目整合不存在问题，但访问时出现**<code>500</code><strong>。则有可能是项目编译缓存问题。（选择开发工具</strong><code>project——————Clean……</code>**可以清楚项目编译缓存）。</li>
</ol>
<h2 id="2-6、SSM整合代码优化"><a href="#2-6、SSM整合代码优化" class="headerlink" title="2.6、SSM整合代码优化"></a>2.6、SSM整合代码优化</h2><ol>
<li>整合中已经将数据源配置迁移至**<code>Spring</code><strong>中了，所以可以将</strong><code>MyBatis</code>**中配置的数据源信息删除。</li>
<li>**<code>Spring</code><strong>核心配置中，加入了映射扫描器配置后，会自动扫描</strong><code>Mapper</code><strong>映射。因此可以将</strong><code>MyBatis</code><strong>核心配置中引入</strong><code>Mapper</code>**映射的步骤删除。</li>
<li>**<code>Spring</code><strong>整合</strong><code>MyBatis</code><strong>，对象的初始化，由</strong><code>Spring</code><strong>管理并注入。所以无需再使用</strong><code>MyBatis</code>**工具类了。</li>
<li>修改**<code>pom.xml</code><strong>统一</strong><code>Spring、Spring MVC、MyBatis</code>**整合版本。（推荐每个不同框架版本都整合）</li>
</ol>
<p>例如：</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>properties</span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- Spring 与 Spring MVC统一版本 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>springmvc.version</span><span class="token punctuation">></span></span>5.2.5.RELEASE<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>springmvc.version</span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- MyBatis统一版本 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mybatis.version</span><span class="token punctuation">></span></span>3.4.6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mybatis.version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>properties</span><span class="token punctuation">></span></span>
-----------------------------------------略----------------------------------------------
<span class="token comment">&lt;!-- #################################   Spring MVC   ################################ --></span>
<span class="token comment">&lt;!-- 引入Spring MVC依赖https://mvnrepository.com/artifact/org.springframework/spring-webmvc --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-webmvc<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>$&#123;springmvc.version&#125;<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>
-----------------------------------------略----------------------------------------------<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h1 id="三、SSM整合扩展"><a href="#三、SSM整合扩展" class="headerlink" title="三、SSM整合扩展"></a>三、SSM整合扩展</h1><p>​    **<code>SSM</code>**整基本工作完成后，可根据需求设计加入其它整合组件，例如：上传，下载，事务控制，异常处理，拦截器等。</p>
<h2 id="3-1、整合加入事务处理"><a href="#3-1、整合加入事务处理" class="headerlink" title="3.1、整合加入事务处理"></a>3.1、整合加入事务处理</h2><p>​    **<code>SSM</code><strong>整合事务操作，可以参照</strong><code>Spring</code><strong>处理事务的方式配置：</strong><code>XML</code><strong>方式配置事务、注解配置事务。（推荐使用</strong><code>XML</code>**方式配置方式）。</p>
<p>修改**<code>Spring</code>**配置文件新增事务管理：</p>
<ol>
<li>配置事务管理器，**<code>MyBatis</code><strong>使用</strong><code>DataSourceTransactionManager</code>**管理事务。</li>
<li>配置事务增强**<code>advice</code>**（配置哪些方式加入事务及事务规则）。</li>
<li>配置切面（将事务增强的配置应用到具体方法）。</li>
</ol>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 1、配置事务管理器 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>transactionManager<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.springframework.jdbc.datasource.DataSourceTransactionManager<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- 注入事务管理数据源 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>dataSource<span class="token punctuation">"</span></span> <span class="token attr-name">ref</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>dataSource<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bean</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- 2、配置事务增强：规则 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">tx:</span>advice</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>txAdvice<span class="token punctuation">"</span></span> <span class="token attr-name">transaction-manager</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>transactionManager<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">tx:</span>attributes</span><span class="token punctuation">></span></span><span class="token comment">&lt;!-- 事务规则 --></span>
    <span class="token comment">&lt;!-- 配置事务管理方法：匹配处理管理的(任意)方法名 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">tx:</span>method</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>*<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">tx:</span>attributes</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">tx:</span>advice</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- 3、配置事务切面：开启事务，将事务管理应用到指定方法（推荐使用XML方式），也可以选择注解方式 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">aop:</span>config</span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- 切入点:表达式方法权限略  回值任意 包名.子级包.任意类.任意方法（任意参数）
 该表达式标识：业务层下的所有包（子级包）下的所有类，所有方法都加入事务 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">aop:</span>pointcut</span> <span class="token attr-name">expression</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>excution(* com.xsge.ssm01.service..*.*(..))<span class="token punctuation">"</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>txPoint<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
  <span class="token comment">&lt;!-- 配置事务增强：使用哪个事务增强，应用到哪个切入点 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">aop:</span>advisor</span> <span class="token attr-name">advice-ref</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>txAdvice<span class="token punctuation">"</span></span> <span class="token attr-name">pointcut-ref</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>txPoint<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">aop:</span>config</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h2 id="3-2、整合加入静态资源处理"><a href="#3-2、整合加入静态资源处理" class="headerlink" title="3.2、整合加入静态资源处理"></a>3.2、整合加入静态资源处理</h2><p>​    <strong><code>Spring MVC</code><strong>加入整合时，配置了前端控制器</strong><code>DispatcherServlet</code><strong>，</strong><code>&lt;url-pattern&gt;</code><strong>拦截请求</strong><code>URL</code><strong>为</strong>“/“<strong>，标识拦截所有请求资源（静态资源被拦截截），在网页设计中当我们引入图片、</strong><code>CSS</code><strong>等静态资源时，被拦截出现</strong>404</strong>问题，可以通过修改**<code>Spring MVC</code>**的核心配置文件处理静态资源不拦截。</p>
<h3 id="3-2-1、方式一（推荐）"><a href="#3-2-1、方式一（推荐）" class="headerlink" title="3.2.1、方式一（推荐）"></a>3.2.1、方式一（推荐）</h3><p>​    修改**<code>Spring MVC</code>**的核心配置文件，添加配置</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 配置将Spring MVC无法处理的请求（404）等交由Tomcat中默认的Servlet处理：资源存在即加载，不存在404 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>default-servlet-handler</span><span class="token punctuation">/></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>

<p>​    前提：配置开启注解驱动（如果之前没有配置请加入如下配置）</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 配置开启注解驱动 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>annotation-driven</span><span class="token punctuation">/></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>

<h3 id="3-2-2、方式二（推荐）"><a href="#3-2-2、方式二（推荐）" class="headerlink" title="3.2.2、方式二（推荐）"></a>3.2.2、方式二（推荐）</h3><p>​    修改**<code>Spring MVC</code>**的核心配置文件，添加配置</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 配置哪些静态资源不拦截 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>resources</span> <span class="token attr-name">location</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/img/<span class="token punctuation">"</span></span> <span class="token attr-name">mapping</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/img/**<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>

<h3 id="3-3-3、方式三（了解）"><a href="#3-3-3、方式三（了解）" class="headerlink" title="3.3.3、方式三（了解）"></a>3.3.3、方式三（了解）</h3><p>​    修改**<code>web.xml</code><strong>重写</strong><code>Tomcat</code><strong>默认拦截配置：</strong><code>&lt;url-pattern&gt;</code>**</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-mapping</span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- 访问指定资源时，使用默认的Servlet处理 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>default<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>*.css<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-mapping</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-mapping</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>default<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>*.js<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-mapping</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-mapping</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>servlet-name</span><span class="token punctuation">></span></span>default<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-name</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>*.jpg<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>servlet-mapping</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="3-3-4、方式四（了解）"><a href="#3-3-4、方式四（了解）" class="headerlink" title="3.3.4、方式四（了解）"></a>3.3.4、方式四（了解）</h3><p>​    修改**<code>web.xml</code><strong>，将前端控制器的</strong><code>&lt;url-pattern&gt;</code><strong>拦截请求方式改为</strong><code>*.do、*.jsp</code>**</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>url-pattern</span><span class="token punctuation">></span></span>*.jsp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>url-pattern</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>

<blockquote>
</blockquote>
<h2 id="3-3、整合加入类型转换器"><a href="#3-3、整合加入类型转换器" class="headerlink" title="3.3、整合加入类型转换器"></a>3.3、整合加入类型转换器</h2><p>​    在注册，添加等操作时，有些需求中涉及到日期数据，这些数据直接封装到**<code>POJO</code>**实体中，框架目前尚不能自动支持，需要手动转换处理。</p>
<h3 id="3-3-1、使用注解-DateTimeFormat"><a href="#3-3-1、使用注解-DateTimeFormat" class="headerlink" title="3.3.1、使用注解@DateTimeFormat"></a>3.3.1、使用注解@DateTimeFormat</h3><p>​    在**<code>POJO</code><strong>实体中或者在控制器方法入参类型前，找到日期类型的属性，在其属性上加入注解</strong><code>@DateTimeFormat</code>**即可</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Custorm</span> <span class="token keyword">implements</span> <span class="token class-name">Serializable</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">private</span> <span class="token class-name">Integer</span> cid<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">String</span> cname<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">String</span> cpassword<span class="token punctuation">;</span>
	<span class="token annotation punctuation">@DateTimeFormat</span><span class="token punctuation">(</span>pattern <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span>
	<span class="token keyword">private</span> <span class="token class-name">Date</span> birthday<span class="token punctuation">;</span>
  <span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span>略<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
<p>[^日期格式化]: @DateTimeFormat(pattern = “yyyy-MM-dd”)自动日期格式化转换注解。pattern表示入参时传入的日期格式、以及格式化格式</p>
</blockquote>
<h3 id="3-3-2、使用自定义类型转换器"><a href="#3-3-2、使用自定义类型转换器" class="headerlink" title="3.3.2、使用自定义类型转换器"></a>3.3.2、使用自定义类型转换器</h3><p>​    略……详情请参考**<code>Spring MVC</code>**课程学习，或私聊发资料视频。</p>
<h4 id="1、编写自定义拦截器。"><a href="#1、编写自定义拦截器。" class="headerlink" title="1、编写自定义拦截器。"></a>1、编写自定义拦截器。</h4><p>​    自定义拦截器要求实现接口**<code>HandlerInterceptor</code>**。</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">InterceptorExtA</span> <span class="token keyword">implements</span> <span class="token class-name">HandlerInterceptor</span> <span class="token punctuation">&#123;</span>
    <span class="token comment">/** 拦截方法
     * 在进入控制器之前执行（在这里编写拦截操作：如登录拦截等）
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">preHandle</span><span class="token punctuation">(</span><span class="token class-name">HttpServletRequest</span> request<span class="token punctuation">,</span> <span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">,</span>  
                             <span class="token class-name">Object</span> handle<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span><span class="token comment">// 表示放行，反之false表示拦截，不放行</span>
    <span class="token punctuation">&#125;</span>

    <span class="token comment">/**后置增强的方法
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">postHandle</span><span class="token punctuation">(</span><span class="token class-name">HttpServletRequest</span> request<span class="token punctuation">,</span>  <span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">,</span>  <span class="token class-name">Object</span> handle<span class="token punctuation">,</span> 
                           <span class="token class-name">ModelAndView</span> modelAndView<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">&#123;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"1.拦截器后置方法postHandle执行.........."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token comment">/**后置增强的方法
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">afterCompletion</span><span class="token punctuation">(</span><span class="token class-name">HttpServletRequest</span> request<span class="token punctuation">,</span> <span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">,</span> 
                                <span class="token class-name">Object</span> handle<span class="token punctuation">,</span> <span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">&#123;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"2.拦截后置方法afterCompletion执行.........."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="2、在SpringMVC核心配置中，配置拦截器"><a href="#2、在SpringMVC核心配置中，配置拦截器" class="headerlink" title="2、在SpringMVC核心配置中，配置拦截器"></a>2、在SpringMVC核心配置中，配置拦截器</h4><p>​    在拦截器配置规则中加入**<code>&lt;mvc:exclude-mappin/&gt;</code>**标签，可以排除不拦截。</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 配置Spring MVC拦截器 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>interceptors</span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- 配置第一个拦截器 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>interceptor</span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!-- 配置拦截器url规则： 拦截单个url：/hello，拦截请求访问控制器路径为/hello方法
           拦截多个url：/** 或者 /user/*，拦截所有 或 拦截/user开头的所有请求--></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>mapping</span> <span class="token attr-name">path</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/**<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
    <span class="token comment">&lt;!-- 配置不被拦截的url规则 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token namespace">mvc:</span>exclude-mappin</span> <span class="token attr-name">path</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/login<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>com.xsge.ssm01.filter.LoginInterceptor<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">mvc:</span>interceptor</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token namespace">mvc:</span>interceptors</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h2 id="3-3、整合加入上传下载"><a href="#3-3、整合加入上传下载" class="headerlink" title="3.3、整合加入上传下载"></a>3.3、整合加入上传下载</h2><p>​    根据项目需求，可能存在上传下载，则在**<code>SSM</code>**整合中加入上传下载。</p>
<h3 id="3-3-1、实现上传前置条件"><a href="#3-3-1、实现上传前置条件" class="headerlink" title="3.3.1、实现上传前置条件"></a>3.3.1、实现上传前置条件</h3><ol>
<li>表单提交方式必须为**<code>POST</code>**；</li>
<li>表单**<code>form</code><strong>标签</strong><code>enctype</code><strong>属性值必须为</strong><code>&quot;multipart/form-data&quot;</code>**；</li>
<li>必须提供上传表单**<code>&lt;input type=&quot;file&quot; name=&quot;fileName&quot;/&gt;</code>**。</li>
</ol>
<h3 id="3-3-2、整合实现上传"><a href="#3-3-2、整合实现上传" class="headerlink" title="3.3.2、整合实现上传"></a>3.3.2、整合实现上传</h3><h3 id="1、引入上传依赖"><a href="#1、引入上传依赖" class="headerlink" title="1、引入上传依赖"></a>1、引入上传依赖</h3><p>​    引入上传组件依赖：**<code>commons-fileupload-1.3.1.jar、commons-io-2.5.jar</code>**</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- #######################  上传组件（自动引入IO依赖）   ###################### --></span>
<span class="token comment">&lt;!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>commons-fileupload<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>commons-fileupload<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.3.1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="2、配置多媒体解析器"><a href="#2、配置多媒体解析器" class="headerlink" title="2、配置多媒体解析器"></a>2、配置多媒体解析器</h3><p>​    修改**<code>Spring MVC</code><strong>配置文件，配置多媒体上传解析器</strong><code>CommonsMultipartResolver</code>**</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 配置文件上传解析器类ommonsMultipartResolver 说明：bean标签属性ID值，必须设定为上传解析器接口（MultipartResolver）的首字母小写  --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>multipartResolver<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.springframework.web.multipart.commons.CommonsMultipartResolver<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- 配置属性 maxUploadSize：设定上传文件大小限制--></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>maxUploadSize<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>10485760<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- 配置属性 maxInMemorySize：设定缓冲区大小--></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>maxInMemorySize<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>4096<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>
  <span class="token comment">&lt;!-- 配置属性 defaultEncoding：设定编码集--></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>defaultEncoding<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>UTF-8<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bean</span><span class="token punctuation">></span></span>	<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="3、在控制器方法中使用参数获取上传文件"><a href="#3、在控制器方法中使用参数获取上传文件" class="headerlink" title="3、在控制器方法中使用参数获取上传文件"></a>3、在控制器方法中使用参数获取上传文件</h3><p>​    参照**<code>Spring MVC</code><strong>文件上传</strong>2.2<strong>。使用</strong><code>MultipartFile</code>**参数解析上传文件。</p>
<h3 id="4、上传文件保存地址问题"><a href="#4、上传文件保存地址问题" class="headerlink" title="4、上传文件保存地址问题"></a>4、上传文件保存地址问题</h3><p>​    上传的文件地址保存问题？ 上传的文件怎么保存？如果直接放入数据库，文件太大，读写数据慢，所以将文件保存在当前项目中最为合适，既可以解决文件保存问题，也可以实现在部署后可以访问。</p>
<ol>
<li>将上传的文件保存在服务器目录下</li>
<li>将上传的文件路径保存在数据库中（方便获取路径访问）</li>
</ol>
<p>需解决的问题：将文件上传在当前项目中，==项目一旦重写部署，文件就丢失了==！！！</p>
<p>A、选择图片服务器保存（大型项目推荐）。</p>
<p>B、配置服务器虚拟目录，作为上传保存的地址（一般中小型项目推荐使用）。</p>
<h3 id="5、配置上传文件保存虚拟目录"><a href="#5、配置上传文件保存虚拟目录" class="headerlink" title="5、配置上传文件保存虚拟目录"></a>5、配置上传文件保存虚拟目录</h3><p>​    找到**<code>Tomcat</code><strong>安装目录，在</strong><code>confg/server.xml</code>**添加如下配置：</p>
<p>​    **<code>docBase</code>**：图片上传保存的位置。</p>
<p>​    **<code>path</code>**：访问的虚拟根路径</p>
<p>​    **<code>reloadable</code>**：是否可重新加载</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Context</span> <span class="token attr-name">docBase</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>D:\*****\ssm-upfile<span class="token punctuation">"</span></span> <span class="token attr-name">path</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>/ssmupfile<span class="token punctuation">"</span></span> <span class="token attr-name">reloadable</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>true<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>

<p>如果使用**<code>Eclipse</code>**开发可以直接在工具中配置：</p>
<p>方式一：选择项目模块中的**<code>Servers</code><strong>项目，这里存放的都是服务器</strong><code>Tomcat</code><strong>的配置文件，可以直接双击打开</strong><code>server.xml</code>**进行配置。</p>
<p>方式二：打开视图**<code>Servers</code><strong>（</strong><code>Tomcat</code><strong>视图），选择服务器双击打开，左下角选择——</strong><code>Modules</code>**配置虚拟地址——保存</p>
<p><img src="/SSM%E6%95%B4%E5%90%88/8%E3%80%81SSM%E6%95%B4%E5%90%88%E9%85%8D%E7%BD%AE%E4%B8%8A%E4%BC%A0%E8%99%9A%E6%8B%9F%E5%9C%B0%E5%9D%80.png" alt="SSM整合配置上传虚拟地址"></p>
<h2 id="3-4、整合加入统一异常处理"><a href="#3-4、整合加入统一异常处理" class="headerlink" title="3.4、整合加入统一异常处理"></a>3.4、整合加入统一异常处理</h2><p>​    异常处理配置分类：局部异常处理和全局配置异常处理。</p>
<h3 id="3-4-1、局部异常处理配置"><a href="#3-4-1、局部异常处理配置" class="headerlink" title="3.4.1、局部异常处理配置"></a>3.4.1、局部异常处理配置</h3><p>​    局部异常处理：当配置后，只能在指定的控制器（Controller）类中处理发生的异常。</p>
<p>​    在控制器（**<code>Controller</code><strong>）类中，提供异常处理方法，在方法上使用注解</strong><code>@ExceptionHandler</code>**，则此控制器中的任意方法中出现异常后，会自动调用该异常处理方法执行。</p>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token comment">// @ExceptionHandler：不给异常类型时，处理所有异常</span>
<span class="token comment">// 指定异常类型：处理指定异常（更加灵活，可以根据不同的异常跳转或显示不同页面）</span>
<span class="token annotation punctuation">@ExceptionHandler</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token class-name">NullPointerException</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">exceptionMethod</span><span class="token punctuation">(</span><span class="token class-name">Exception</span> exception<span class="token punctuation">,</span><span class="token class-name">Model</span> model<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"出错了，异常信息为："</span><span class="token operator">+</span>exception<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"出错了，异常类型为："</span><span class="token operator">+</span>exception<span class="token punctuation">.</span><span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token comment">// 将异常信息发送给页面</span>
  model<span class="token punctuation">.</span><span class="token function">addAttribute</span><span class="token punctuation">(</span><span class="token string">"msg"</span><span class="token punctuation">,</span> exception<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">return</span> <span class="token string">"error"</span><span class="token punctuation">;</span><span class="token comment">// Spring MVC视图解析器处理调用到错误页面errot.jsp</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
</blockquote>
<h3 id="3-4-2、全局配置异常处理"><a href="#3-4-2、全局配置异常处理" class="headerlink" title="3.4.2、全局配置异常处理"></a>3.4.2、全局配置异常处理</h3><p>​    全局异常处理：当配置后，任意控制器（Controller）类中任意位置出现异常，都进行处理。概括有三种方式。</p>
<h4 id="1、自定义异常类，注解配置方式"><a href="#1、自定义异常类，注解配置方式" class="headerlink" title="1、自定义异常类，注解配置方式"></a>1、自定义异常类，注解配置方式</h4><ol>
<li>编写普通java类</li>
<li>在类上使用注解**<code>@ControllerAdvice</code>**。（控制器增强注解）</li>
<li>在类中编写异常处理方法。</li>
<li>在方法上使用注解**<code>@ExceptionHandler</code>**（异常处理器注解）</li>
</ol>
<pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token annotation punctuation">@ControllerAdvice</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">GlobalExceptionHandler</span> <span class="token punctuation">&#123;</span>

	<span class="token comment">// @ExceptionHandler：不给异常类型时，处理所有异常</span>
	<span class="token comment">// 指定异常类型：处理指定异常（更加灵活，可以根据不同的异常跳转或显示不同页面）</span>
	<span class="token annotation punctuation">@ExceptionHandler</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token class-name">NullPointerException</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
	<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">exceptionMethod</span><span class="token punctuation">(</span><span class="token class-name">Exception</span> exception<span class="token punctuation">,</span><span class="token class-name">Model</span> model<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"出错了："</span><span class="token operator">+</span>exception<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 将异常信息发送给页面</span>
		model<span class="token punctuation">.</span><span class="token function">addAttribute</span><span class="token punctuation">(</span><span class="token string">"msg"</span><span class="token punctuation">,</span> exception<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token string">"error"</span><span class="token punctuation">;</span><span class="token comment">// Spring MVC视图解析器处理调用到错误页面errot.jsp</span>
	<span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="2、全局异常处理，xml配置方式（推荐使用）"><a href="#2、全局异常处理，xml配置方式（推荐使用）" class="headerlink" title="2、全局异常处理，xml配置方式（推荐使用）"></a>2、全局异常处理，xml配置方式（推荐使用）</h4><p>​    修改**<code>Spring MVC</code><strong>核心配置文件，加入全局异常处理配置：</strong><code>SimpleMappingExceptionResolver</code><strong>（由</strong><code>Spring3.0</code>**及之后版本提供）</p>
<pre class="line-numbers language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 配置全局异常处理 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bean</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> 
  <span class="token comment">&lt;!-- 为所有的异常定义默认的异常处理页面，exceptionMappings未定义的异常使用本默认配置 --></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>defaultErrorView<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>error<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>  
  <span class="token comment">&lt;!-- 定义异常处理页面用来获取异常信息的变量名，默认名为exception 这里取名ex JSP中可以使用ex对象获取异常信息--></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>exceptionAttribute<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>ex<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>  
  <span class="token comment">&lt;!-- 定义需要特殊处理的异常，用类名或全路径名作为key，jsp文件名作为值，将不同的异常映射到不同的页面上。--></span>  
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>exceptionMappings<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>props</span><span class="token punctuation">></span></span>  
      <span class="token comment">&lt;!-- 这里配置的文件地址映射名无需以“/”开头，对应的是当前web根目录 --></span>
      <span class="token comment">&lt;!-- 说明：想要该配置的生效，给定的异常类型必须为抛出异常的终极类型，所以测试时出现的不生效可能是异常类型有问题 --></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>prop</span> <span class="token attr-name">key</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>IOException<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>error/ioexp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>prop</span><span class="token punctuation">></span></span>  
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>prop</span> <span class="token attr-name">key</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>java.sql.SQLException<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>error/sqlexp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>prop</span><span class="token punctuation">></span></span>  
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>props</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bean</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<blockquote>
<p>可以在异常处理局部配置中，先打印异常类型，再将异常类型放入该配置中测试。</p>
</blockquote>
<h4 id="3、自定义异常类，异常处理器配置方式（推荐使用）"><a href="#3、自定义异常类，异常处理器配置方式（推荐使用）" class="headerlink" title="3、自定义异常类，异常处理器配置方式（推荐使用）"></a>3、自定义异常类，异常处理器配置方式（推荐使用）</h4><ol>
<li>自定义异常信息管理类。</li>
<li>自定义异常类处理器（实现接口**<code>HandlerExceptionResolver</code>**）。</li>
<li>修改**<code>Spring MVC</code>**核心配置文件配置异常处理器。</li>
<li>修改控制器方法当出现异常抛出自定义异常类对象。</li>
</ol>
<p>==此处代码省略，详情参阅<strong>Spring MVC</strong>高级四、统一异常处理==</p>
<blockquote>
<p>[^异常处理器说明]: 自定义异常处理器，要求实现接口**<code>HandlerExceptionResolver</code><strong>，实际在</strong><code>Spring3.0</code>**及之后版本提供了默认的实现类 **<code>SimpleMappingExceptionResolver</code>**，如上一种异常处理配置便是。</p>
</blockquote>

            </div>
            <hr/>

            
            <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.88rem;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-large waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fa fa-close"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力!</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.bmp" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.bmp" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            

            <!-- 分享插件 -->
<link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
        <div class="social-share" data-disabled="qzone"  data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>">
        分享：
        </div>
    
</div>
<!-- 分享插件 xsge-JS -->
<script src="/libs/share/js/social-share.min.js"></script>

            
            
            
            <div class="reprint1">
                <p>
                    <span class="reprint1-tip">
                        <i class="fa fa-exclamation-circle"></i>&nbsp;&nbsp;转载请注明:
                    </span>
                    <a href="https://xsge.gitee.io/sasa" class="b-link-green">のブログ</a>
                    <i class="fa fa-angle-right fa-lg fa-fw text-color"></i>
                    <a href="/sasa/2021/09/12/SSM%E6%95%B4%E5%90%88/" class="b-link-green">SSM整合</a>
                </p>
            </div>

        </div>
    </div>

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fa fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/sasa/2022/09/14/hello-world/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/12.jpg" class="responsive-img" alt="Hello World">
                        
                        <span class="card-title">Hello World</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hex
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2022-09-14
                        </span>
                        <span class="publish-author">
                            
                        </span>
                    </div>
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fa fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/sasa/2019/08/27/Blog-Open-Source/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/8.jpg" class="responsive-img" alt="ササ">
                        
                        <span class="card-title">ササ</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            测试测试时测试出实测
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2019-08-27
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/sasa/categories/%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE%E5%88%86%E7%B1%BB/" class="post-category" target="_blank">
                                    软件安装与配置分类
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/sasa/tags/%E6%97%A5%E6%96%99/" target="_blank">
                        <span class="chip bg-color">日料</span>
                    </a>
                    
                    <a href="/sasa/tags/Gitee/" target="_blank">
                        <span class="chip bg-color">Gitee</span>
                    </a>
                    
                    <a href="/sasa/tags/%E5%8D%9A%E5%AE%A2/" target="_blank">
                        <span class="chip bg-color">博客</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: のブログ<br />'
            + '作者: ササ<br />'
            + '链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="fa fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. 阅读的时候,哪个目录悬浮按钮  和   回到顶部在一块-->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fa fa-list"></i>
    </a>
</div>


<script src="https://libs.jshub.com/tocbot/4.18.2/tocbot.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h1, h2, h3, h4, h5'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1, h2, h3, h4, h5').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).slideUp(500);
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).slideDown(500);
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>
    

</main>


        <footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            Copyright&copy; 2019 XSGE.

            <span id="sitetime"></span><span class="my-face"></span>
            <br>

            

            
                    
                        <span id="busuanzi_container_site_pv" style='display:none'></span>
                        总访问量: <span id="busuanzi_value_site_pv" class="white-color"></span>
                    
        
                    
                        <span id="busuanzi_container_site_uv" style='display:none'></span>
                        人次&nbsp; | &nbsp;访客人数: <span id="busuanzi_value_site_uv" class="white-color"></span> 人
                    
    
            

            
                &nbsp; | &nbsp;字数统计:&nbsp;
                <span class="white-color">13.7k</span> 字
            

            
            <br>

        </div>

        <div class="col s12 m4 l4 social-link social-statis"><!-- GIT图标 -->

    <a href="https://github.com/xsge" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fa fa-github"></i>
    </a>

<!-- 邮件 -->
 
    <a href="https://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=1511868921@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fa fa-envelope-open"></i>
    </a>


<!-- 知乎 -->

<!-- QQ -->

    <a href="http://wpa.qq.com/msgrd?v=3&uin=1511868921&site=qq&menu=yes" class="tooltipped" target="_blank" data-tooltip="访问我的QQ空间" data-position="top" data-delay="50">
        <i class="fa fa-qq"></i>
    </a>

<!-- 微博 -->

<!-- 网页版：无法发起微信  -->

<!-- 订阅 -->

    <a href="/sasa/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fa fa-rss"></i>
    </a>
</div>

    </div>
</footer>

<div class="progress-bar"></div>
<script language=javascript>
    function siteTime() {
        window.setTimeout("siteTime()", 1000);
        var seconds = 1000;
        var minutes = seconds * 60;
        var hours = minutes * 60;
        var days = hours * 24;
        var years = days * 365;
        var today = new Date();
        var todayYear = today.getFullYear();
        var todayMonth = today.getMonth() + 1;
        var todayDate = today.getDate();
        var todayHour = today.getHours();
        var todayMinute = today.getMinutes();
        var todaySecond = today.getSeconds();

        // Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
        // year - 作为date对象的年份，为4位年份值
        // month - 0-11之间的整数，做为date对象的月份
        // day - 1-31之间的整数，做为date对象的天数
        // hours - 0(午夜24点)-23之间的整数，做为date对象的小时数
        // minutes - 0-59之间的整数，做为date对象的分钟数
        // seconds - 0-59之间的整数，做为date对象的秒数
        // microseconds - 0-999之间的整数，做为date对象的毫秒数

        var t1 = Date.UTC(2019, 08, 10, 00, 00, 00); //北京时间2019-8-1 00:00:00
        var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
        var diff = t2 - t1;
        var diffYears = Math.floor(diff / years);
        var diffDays = Math.floor((diff / days) - diffYears * 365);
        var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
        var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) / minutes);
        var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours - diffMinutes *
            minutes) / seconds);
        document.getElementById("sitetime").innerHTML = "本站已勉强运行 " + diffYears + " 年 " + diffDays + " 天 " + diffHours +
            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒" ;
    } /*因为建站时间还没有一年，就将之注释掉了。需要的可以取消*/
    siteTime();
</script>


        <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fa fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/sasa/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
        <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


        <script src="https://cdn.bootcss.com/materialize/1.0.0/js/materialize.min.js"></script>
        <script src="https://cdn.bootcss.com/masonry/4.2.2/masonry.pkgd.min.js"></script>
        <script src="https://cdn.bootcss.com/aos/3.0.0-beta.6/aos.js"></script>
        <script src="https://cdn.bootcss.com/scrollprogress/3.0.2/scrollProgress.min.js"></script>
        <script src="https://cdn.bootcss.com/lightgallery/1.6.12/js/lightgallery-all.min.js"></script>
        <script src="/js/matery.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js"></script>

        <!-- Global site tag (gtag.js) - Google Analytics xsge_JS -->
<!-- 添加 Google Analytics（站流量统计分析工具） 配置 -->



        
            <script src="/libs/others/clicklove.js"></script>
        

        
            <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
        

        <!-- XSGE 网页地址栏信息 shw2018 add 2019.08.28 -->
        <script type="text/javascript">
            var OriginTitile = document.title,
                st;
            document.addEventListener("visibilitychange", function () {
                document.hidden ? (document.title = "看不见我🙈~看不见我🙈~", clearTimeout(st)) : (document.title =
                    "(๑•̀ㅂ•́) ✧被发现了～", st = setTimeout(function () {
                        document.title = OriginTitile
                    }, 3e3))
            })
        </script>

        <!-- 鼠标点击烟花爆炸效果  XSGE shw2018 add 2019.09.09 -->
        

        <!-- 背景雪花飘落特效  XSGE shw2018 add 2019.09.10 -->
        
            <script type="text/javascript">
            //只在桌面版网页启用特效
            var windowWidth = $(window).width();
            if (windowWidth > 768) {
                document.write('<script type="text/javascript" src="/js/sakura.js"><\/script>');
            }
            </script>
        

        <!-- 鼠标点击文字特效 XSGE shw2018 add 2019.09.10-->
        
            <script src="/js/wenzi.js" type="text/javascript"></script>
        

        <!-- 背景雪花飘落特效 XSGE shw2018 add 2019.09.10 -->
        
            <script type="text/javascript">
                var windowWidth = $(window).width();
                if (windowWidth > 768) {
                    document.write('<script type="text/javascript" src="/js/xuehuapiaoluo.js"><\/script>');
                }
            </script>
        

        <!-- 在线聊天工具  XSGE shw2018 add 2019.09.11  xsge_JS-->
        

        <!-- 背景 canvas-nest  XSGE shw 2018  add 2019.09.15-->
        
            <script type="text/javascript">
            var windowWidth = $(window).width();
            if (windowWidth > 992) {
                document.write('<script type="text/javascript" color="200,147,255" pointColor="0,0,255" opacity= "0.8" zIndex="--1" count="150"src="/libs/background/canvas-nest.js"><\/script>');
            }
            </script>
        

        <!-- 背景静止彩带  XSGE shw 2018  add 2019.09.15-->
        
            <script type="text/javascript">
            var windowWidth = $(window).width();
            if (windowWidth > 992) {
                document.write('<script type="text/javascript" size="150" alpha="0.6" zIndex="-1" src="/libs/background/ribbon.min.js"><\/script>');
            }
            </script>
        

        <!-- 背景动态彩带 XSGE shw 2018  add 2019.09.15-->
        
            <script type="text/javascript">
            var windowWidth = $(window).width();
            if (windowWidth > 992) {
                document.write('<script type="text/javascript" src="/libs/background/ribbon-dynamic.js"><\/script>');
            }
            </script>
        

    </body>
</html>